views:

178

answers:

5

How can i show this? substring?split? ...

but it's maybe dynamic !!!

String str = "SET ENCALSUP=NOENCR&GSMV2,MAXNCELL=16,TDTMWIND=5,MAXLAPDMN=5,EENHDTMSUP=DISABLED,T3197=4,PAGCOORCLB=DISABLED,DGRSTRGYBCNT=DISABLED,PAGQOVLIND=0;";

this output (EENHDTMSUP=DISABLED):

just this

DISABLED

Thanks ...

+1  A: 

Is this what you're looking for?

StringTokenizer tokenizer = new StringTokenizer(str.substring(4),",");
while(tokenizer.hasMoreTokens()){
    System.out.println(tokenizer.nextToken());
}
Michael Krauklis
The Elite Gentleman
I had removed the "SET" with the substring on the string passed to the tokenizer constructor. This shouldn't be an issue.
Michael Krauklis
Although it doesn't look like this is what the poster was asking for. Oh well.
Michael Krauklis
Sorry, I've missed your substring(4) in your StringTokenizer constructor.
The Elite Gentleman
+4  A: 

Your question isn't very clear. Do you just need to know the value of "EENHDMSUP"?

If so, something like:

int start = myString.indexOf("EENHDTMSUP=");
String substr = myString.subString(start,myString.indexOf(',',start);
System.out.println(substr);

Would probably work.

Chad Okere
thanks dear Chad :-)
Mike Redford
Dear Chad how can i export just value for example in this case just it : "DISABLED"
Mike Redford
A: 

Not sure what you meant by "but it's maybe dynamic." But if the string always follows that format and "EENHDTMSUP=DISABLED" stays at that same index in the string, then you can use:

String output = str.Split(',')[4];
madatanic
A: 

Why don't you try?

String[] strings = str.split(",");

for (String s:strings) {
    if (s.toLowerCase().startsWith("set ")) {
        s = s.substring("set ".length());
    }

    System.out.println(s);
}

Using regular expressions of course ;)

The Elite Gentleman
A: 

Looking for REGEX?

Ein2015