 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Thu May 03, 2012 10:06 am Post subject: [Java] string.replaceAll() isn't working.... |
|
|
Code: | String s = " 4 . 5 3 2 ";
s = s.replaceAll("\\s+","");
//s = s.replaceAll(" ", ""); //alternative
System.out.println(s); |
Prints 4.532
Yet
Code: |
s[i] = s[i].replaceAll("\\s+","");
s[i] = s[i].replaceAll(" ", ""); // alternative doesnt work either
System.out.println(s[i]);
|
where S[i] = " 4 . 5 3 2 ". it still prints out 4 . 5 3 2 , not 4.532 like it should...
Any ideas why? My sanity is on the line here
_________________
|
|
Back to top |
|
 |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Thu May 03, 2012 12:00 pm Post subject: |
|
|
Works fine for me.
Code: |
String[] s = new String[] {" 4 . 5 3 2 "};
s[0] = s[0].replaceAll("\\s+","");
System.out.println(s[0]);
|
Output: 4.532
|
|
Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Thu May 03, 2012 1:00 pm Post subject: |
|
|
String [] s = { "4 . 5 6", "2. 6 8", "3 . 6 3", .....} and so on which I got by .split() ing a larger string into those individual strings).
Then I'm passing s into a function:
public static double myFuncccction(String[] s, int low, int high){
for(int i = low; i<high; i++){
System.out.println(s[i]);
g[i] = s[i].trim(); //optional
g[i] = s[i].replaceAll("\\s+","");
g[i] = s[i].replaceAll(" ", "");
System.out.println(s[i]);
}
I just want the strings to be "4.56" and so on, without white spaces, so I can convert them to a double for other uses.
However it prints out the same before and after the call to .replaceAll()
_________________
|
|
Back to top |
|
 |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Thu May 03, 2012 2:13 pm Post subject: |
|
|
manc wrote: | String [] s = { "4 . 5 6", "2. 6 8", "3 . 6 3", .....} and so on which I got by .split() ing a larger string into those individual strings).
Then I'm passing s into a function:
public static double myFuncccction(String[] s, int low, int high){
for(int i = low; i<high; i++){
System.out.println(s[i]);
g[i] = s[i].trim(); //optional
g[i] = s[i].replaceAll("\\s+","");
g[i] = s[i].replaceAll(" ", "");
System.out.println(s[i]);
}
I just want the strings to be "4.56" and so on, without white spaces, so I can convert them to a double for other uses.
However it prints out the same before and after the call to .replaceAll() |
What is 'g'? You are outputting 's'.
|
|
Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Thu May 03, 2012 2:19 pm Post subject: |
|
|
Blacknight wrote: | manc wrote: | String [] s = { "4 . 5 6", "2. 6 8", "3 . 6 3", .....} and so on which I got by .split() ing a larger string into those individual strings).
Then I'm passing s into a function:
public static double myFuncccction(String[] s, int low, int high){
for(int i = low; i<high; i++){
System.out.println(s[i]);
g[i] = s[i].trim(); //optional
g[i] = s[i].replaceAll("\\s+","");
g[i] = s[i].replaceAll(" ", "");
System.out.println(s[i]);
}
I just want the strings to be "4.56" and so on, without white spaces, so I can convert them to a double for other uses.
However it prints out the same before and after the call to .replaceAll() |
What is 'g'? You are outputting 's'. |
just an accident, they should be s's
_________________
|
|
Back to top |
|
 |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Thu May 03, 2012 2:53 pm Post subject: |
|
|
Again it works perfectly fine.
Code: |
public static double myFuncccction(String[] s, int low, int high) {
for(int i = low; i < high; i++) {
System.out.println(s[i]);
s[i] = s[i].trim(); //optional
s[i] = s[i].replaceAll("\\s+","");
s[i] = s[i].replaceAll(" ", "");
System.out.println(s[i]);
}
return 0.0d;
}
|
Code: |
String [] s = { "4 . 5 6", "2. 6 8", "3 . 6 3"};
myFuncccction(s, 0, s.length);
|
Output:
Code: |
4 . 5 6
4.56
2. 6 8
2.68
3 . 6 3
3.63
|
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|