刚刚在string字符串资源文件里,写了一个单引號。报错了,错误代码例如以下

 

error: Apostrophe not preceded by \ (in OuyangPeng's blog )

我的Android进阶之旅------>Android字符串资源中的单引號问题error: Apostrophe not preceded by 的解决的方法_资源文件

资源文件例如以下:

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="ouyang">OuyangPeng's blog </string>
    <string name="blog"> javascript:void(0)</string>
</resources>

解决方法有两种。例如以下所看到的:

第一种方法:使用双引號将单引號的字符串资源括起来,例如以下所看到的:

 

<string name="ouyang">"OuyangPeng's blog" </string>

另外一种方法:在 ’ 号之前要加 \进行转义 ,这样做是为了避免歧义。例如以下所看到的:

 

 

<string name="ouyang">OuyangPeng\'s blog </string>

 

 

 


 


                            ====================================================================================

  作者:欧阳鹏 

====================================================================================