You are not logged in.
Announcement
Unanswered posts
|
Pages: 1

Hi,
I want to cut a string and to take a part of it between '*'...
exple I have
aaaa aa * bb *cccc * dddd
So I what only 'bb'
So I try :
fields != null &&fields.matches("[\\*]")?
fields. split("[\\*]")[1]:"11"
:"22"
It doesn't work I always have '11'
I MUST test if '*' exist because some time my field is like :
"aaa freigeoghogn" without '*' ..
Thanks for help...
Working on :
TIS 2.4.1 r16077
Last edited by fwalle (2008-12-01 16:26:55)
Offline

Use the following code because the matches method try to match the entire string:
... fields.matches(".*\\*.*") ...else you could use
... fields.contains("*") ...Last edited by amaumont (2008-12-01 18:38:18)
Offline
Hello fwalle
Do you want to get the string only between the first * and the second *?
if so, here is a routine:
// template routine Java
package routines.ff;
public class myRoutines {
public static String cutString(String message){
int length = message.length();
int firstMark = 0;
int secondMark = 0;
int numMark = 0;
String result = null;
String s;
for (int i = 0; i < length; i++) {
if (numMark == 2) {
break;
}
s = message.substring(i, i + 1);
if (s.equals("*")) {
numMark++;
if (numMark == 1) {
firstMark = i;
} else {
secondMark = i;
}
}
}
if (numMark == 2) {
result = message.substring(firstMark + 1, secondMark);
return result.trim();
} else {
return null;
}
}
}Best regards
shong
Offline
Pages: 1