从编码字符串比较当前日期

时间:2018-05-24 06:33:15

标签: swift string

我有json响应,它有不同的语言,我想比较一天;当我选择语言土耳其语时会得到如下响应:

sunday = {
    day = Pazar;
    timings = (
                    {
            endTime = "23:59:00";
            id = 100000174;
            startTime = "11:58:00";
    }
    );
};
wednesday = {
    day = "\U00e7ar\U015famba";
    timings = (
                    {
            endTime = "22:00:00";
            id = 100000177;
            startTime = "13:00:00";
    }
    );
};

I want to compare them the following way:

if(day.lowercased() == “\U00e7ar\U015famba”) {
    //get Wednesday day
    //this condition work in Sunday Dictionary
}

但是它显示错误“无效的转义序列”“闭包表达式未使用” Please see this image

1 个答案:

答案 0 :(得分:0)

在Swift中,\ u转义序列之后的十六进制值需要用大括号括起来(\ u为小写):

"\u{00e7}ar\u{015f}amba"

这就是你得到错误的原因。

但是,如果您要与从JSON返回的值进行比较,而JSON不遵循此格式,则您需要双重转义\ U以将它们作为纯字符串进行比较:

if day.lowercased() == "\\U00e7ar\\U015famba" {
 ...
}