Results 1 to 5 of 5
Thread: String.replace ?!
- 08-21-2011, 04:26 PM #1
String.replace ?!
public String repeatSeparator(String word, String sep, int count) {
String v = "";
for(int i=1;i<=count;i++){
v += word + sep;
}
v = v.replace(v.substring(v.lastIndexOf(sep), v.length()), "");
return v;
}
=======================
this is my code and i wanna delete last sep .... how can i do that?Last edited by HearT.Hunt3r; 08-21-2011 at 04:31 PM.
-
Check out the String#replace API. It replaces all occurrences of the target sequence.
- 08-21-2011, 04:38 PM #3
i would do that by replace function but i couldn't and i did this and fixed :
v = v.substring(0, v.lastIndexOf(sep));Last edited by HearT.Hunt3r; 08-22-2011 at 03:07 PM.
- 08-22-2011, 02:52 AM #4
Alternatively you could add the separator before each word except the first. Also, you might want to look into using a StringBuilder instead of all those String concatenations.
- 08-22-2011, 03:04 AM #5
Similar Threads
-
Java String Replace
By aham in forum New To JavaReplies: 4Last Post: 05-17-2011, 08:46 AM -
Replace String
By Raeghin in forum New To JavaReplies: 1Last Post: 07-28-2009, 03:58 PM -
replace a string using Text i/o
By PureAwesomeness in forum New To JavaReplies: 9Last Post: 07-06-2009, 02:38 AM -
string replace problem
By soni in forum Advanced JavaReplies: 8Last Post: 07-06-2008, 01:21 AM -
String replace method
By venkata.tarigopula in forum Advanced JavaReplies: 1Last Post: 07-10-2007, 08:14 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks