Skip to Main Content

Java String indexOf Parsing

2801625Dec 24 2014 — edited Jan 2 2015

In the code below I am splitting the String relativeDN at the "," character. After splitting the String I need to parse the string from the "=" character using indexof

and then rebuild the string. I was able to parse the first = sign then rebuild the string but it doesnt remove the subsequent = character. Im trying to parse the string

using idexof for all the "=" characters and then rebuild it using StringBuilder.  Any help is greatly appreciated.

public class StringTestProgram {

public static void main(String[] args) {

  String relativeDN = "cn=abc,dn=xyz,ou=abc/def";

  //Split String

  String[] stringData = relativeDN.split(",");

  {

  StringBuilder sb = new StringBuilder();

  CharSequence charAdded = ",";

  // loop thru each element of the array

  for (int place = 0; place < stringData.length; place++) {

  System.out.println(stringData[place]);

  {

  char equals = '=';

  int result;

  result = relativeDN.indexOf(equals);

  String sub = relativeDN.substring(result +1);

  System.out.println(sub);

  }

Comments
Post Details
Added on Dec 24 2014
4 comments
1,445 views