0

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 ...

3
  • I'm a little confused. Do you want to show each key->value pair? Commented Feb 1, 2010 at 19:29
  • 12
    You haven't specified on what criteria the sub-string should be selected. Currently the answer to your question is System.out.println("EENHDTMSUP=DISABLED"). Commented Feb 1, 2010 at 19:30
  • java.sun.com/docs/books/tutorial/essential/regex Commented Aug 28, 2012 at 10:04

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Is this what you're looking for?

StringTokenizer tokenizer = new StringTokenizer(str.substring(4),",");
while(tokenizer.hasMoreTokens()){
    System.out.println(tokenizer.nextToken());
}

4 Comments

Your first tokenizer.nextToken() will display this: "SET ENCALSUP=NOENCR&GSMV2". I think he wants the "SET" removed.
I had removed the "SET" with the substring on the string passed to the tokenizer constructor. This shouldn't be an issue.
Although it doesn't look like this is what the poster was asking for. Oh well.
Sorry, I've missed your substring(4) in your StringTokenizer constructor.
0

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];

Comments

0

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 ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.