Carlos
Carlos

Reputation: 117

Manipulating StringBuilder() string

I am trying to search for regular expressions in a string created by StringBuilder() as follows

public String config( String langage ) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader (dir_user+"/.prochic/"+langage));

    //System.out.println(getAbsolutePath());
    String         line = null;
    StringBuilder  stringBuilder = new StringBuilder();
    String         ls = System.getProperty("line.separator");

    try {
    while( ( line = reader.readLine() ) != null ) {
        stringBuilder.append( line );
        stringBuilder.append( ls );
    }

    return stringBuilder.toString();

    } finally {
    reader.close();
    }
};

and then

String text=config(langage);

However, I can't do something like

System.out.println(text[5]);

How can I access (or print) the different components (characters) of my string?

Upvotes: 0

Views: 83

Answers (1)

Idos
Idos

Reputation: 15310

I think you are looking for .charAt():

System.out.println(text.charAt(5));

Upvotes: 2

Related Questions