添加一些元素到edittext,即任何单词之间的某些字符

时间:2014-12-28 15:18:23

标签: android

我需要从edittext接收用户的输入,然后在其中添加一些元素? 我怎么能以编程方式做到这一点? 让我解释: 用户输入以下短语:( Hello World) 我希望我的应用将其更改为:(H o el p lo m w w o e 例如, l d c ) 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

从您的edittext

获取文字
String userInput = myEditText.getText().toString();

然后根据需要修改

要“修改”字符串,您可以通过多种方式完成

您可以使用子字符串,replace(),... etc

你也可以将它转换为char数组并修改它,然后重新构建你的字符串

String userInput = myEditText.getText().toString();
char[] myArray = userInput.toCharArray();
// your modification(s) here
userInput = new String(myArray);