试图将看起来像“ÐавлÑкÐÑкÑоє的字符串转换成正确的字符串

时间:2016-05-07 09:42:14

标签: swift unicode encoding

我在将字符串看起来像“ÐавлÑкÐÑкÑоє转换成正确的字符串时遇到了问题。

我正试图用这种方式:

$data = array();
while($row = mysqli_fetch_array($result))
{
    $data[$row["term_no"]][] =  array(
        'code' => $row["code"],
        'grade' => $row["grade"]
    );

}


echo '<table width="200" border="1">';
   echo "<tr>";
   echo "<th>courses</th>";
   echo "<th>terms</th>";
   echo "<th>grades</th>";
   echo "</tr>";

foreach($data as $term=>$otherrow) {
    $count = 0;
    foreach ($otherrow as $data) {
        if($count == 0) {
            echo "<tr>";
            echo "<td>" . $data["code"]. "</td>";
            echo '<td rowspan="'.count($otherrow).'">' . $term. '</td>';
            echo "<td>" . $data["grade"]. "</td>";
            echo "</tr>";
        }else {
            echo "<tr>";
            echo "<td>" . $data["code"]. "</td>";
            echo "<td>" . $data["grade"]. "</td>";
            echo "</tr>";
        }
        $count++;
    }
}
echo "</table>";

但是我得到了一个编译器错误:“该行的表达类型是更多的上下文”:

func stringToUTF16String (stringaDaConvertire stringa: String) -> String {

        let encodedData = stringa.dataUsingEncoding(NSUTF16StringEncoding)!
        let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType]
       let attributedString = NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil, error: nil)!


        //println(attributedString.string)
        return attributedString.string
    }

0 个答案:

没有答案