Reputation: 91
i have problem how to , remove the comma in the of my output. I use replaceall but it doesnt remove the comma , this my code
public void onClick(View v) {
String space = "";
String foo = " ";
String foo1 = ",";
String sentences = null;
//Splitting the sentence into words
sentences = multiple.getText().toString().toLowerCase();
String[] splitwords = sentences.trim().split("\\s+");
for (String biyak : splitwords) {
foo = (foo + "'" + biyak + "'" + foo1);
foo.replaceAll(",$", " ");//foo.replaceAll();
wordtv.setText(foo);
My codes Output : 'Hello','world', My desire output: 'Hello','world'
Upvotes: 0
Views: 114
Reputation: 54204
String
instances are immutable. As a result, methods like replaceAll()
do not modify the original string but instead return a modified copy of the string. So replace foo.replaceAll(...)
with foo = foo.replaceAll(...)
.
Upvotes: 1
Reputation: 3
U can also use a if statement and traverse the whole string . If a comma(,) is found replace it with a space(" ").
Upvotes: 0
Reputation: 561
you can use substring method of String class. or You can use deleteCharAt() method of StringBuilder or StringBuffer classStringBuffer sb=new StringBuffer(your_string);sb.deleteCharAt(sb.length()-1);
Upvotes: 0