操作StringBuilder()字符串

时间:2016-02-15 14:08:47

标签: java

我正在尝试在StringBuilder()创建的字符串中搜索正则表达式,如下所示

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

然后

String text=config(langage);

但是,我不能做像

这样的事情
System.out.println(text[5]);

如何访问(或打印)字符串的不同组件(字符)?

1 个答案:

答案 0 :(得分:2)

我认为您正在寻找.charAt()

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