【发布时间】:2016-02-29 06:20:29
【问题描述】:
我想知道如何以编程方式在 android 中编辑字符串。我正在从我的设备显示字符串到我的网站,而撇号破坏了 PHP 输出。所以为了解决这个问题,我需要添加字符中断,即:反斜杠'\'。
例如,如果我有这个字符串:I love filiberto's!
我需要 android 来编辑它:I love filiberto\'s!
但是,每个字符串都会有所不同,并且还会有其他字符我必须从 .我怎样才能做到这一点?
我想知道如何以编程方式在 android 中编辑字符串。我正在从我的设备显示字符串到我的网站,而撇号破坏了 PHP 输出。所以为了解决这个问题,我需要添加字符中断,即:反斜杠'\'。
这是我目前所拥有的,感谢 ANJ 的基本代码...:
if(title.contains("'")) {
int i;
int len = title.length();
char[] temp = new char[len + 1]; //plus one because gotta add new
int k = title.indexOf("'"); //location of apostrophe
for (i = 0; i < k; i++) { //all the letters before the apostrophe
temp[i] = title.charAt(i); //assign letters to array based on index
}
temp[k] = 'L'; // the L is for testing purposes
for (i = k+1; i == len; i++) { //all the letters after apostrophe, to end
temp[i] = title.charAt(i); //finish the original string, same array
}
title = temp.toString(); //output array to string (?)
Log.d("this is", title); //outputs gibberish
}
它输出随机字符..甚至与我的起始字符串不相似。有谁知道这可能是什么原因造成的?例如,字符串“Lol'ok”变成>>“%5BC%4042ed0380”
【问题讨论】:
标签: android string insert edit