StringBuilder到字符串数组如何转换 [英] StringBuilder to Array of Strings how to convert

查看:230
本文介绍了StringBuilder到字符串数组如何转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法找到或阅读有关此问题的任何信息(这仅对我来说是个问题,但也许有人知道可以解决此问题的方法.

cant anything find or read about this problem ( it's problem only for me but maybe someone know way to fix it.

我具有从资产文件夹读取的功能

i have function which reading from asset folder

public String[] loadFromAsset() throws IOException
    {
        String TEMPBUFFER = null;
        String[] temp;
        temp = new String[60];
        int tempc = 0;
        BufferedReader bReader = new BufferedReader(new InputStreamReader(cont.getAssets().open("myquests.txt")));
        String line="";//  = bReader.readLine();
        StringBuilder sb = new StringBuilder();
        while (line != null) {

            line = bReader.readLine();
            sb.append(line).append("TABTAB");
            tempc++;
  }
         bReader.close();
    //convert SB to array here
         saveCount(tempc-1);
         return temp;

    }

需要返回字符串数组,例如temp [50] =(1,2,3,4,5,... n + 1) 但是我找不到从stringBuilder转换为array的方法:( 拜托,也许有人知道.告诉我

Need return array of strings like temp[50] = (1,2,3,4,5,...n+1) But i can't find a way to convert from stringBuilder to array :( Please,maybe anyone know it. Tell me

只需将SB作为数组返回(如temp [])或将SB转换为Array,如sb-> convert-> temp []

Just need return SB as a array (like temp[]) or convert SB to Array here like sb->convert->temp[]

推荐答案

temp = sb.toString().split("TABTAB");将拆分字符串,并为每行返回一个字符串数组.但是我不能完全确定这是您要尝试做的...

temp = sb.toString().split("TABTAB"); will split the string and return an array of strings for each line. But Iäm not completely sure that this is what you are trying to do...

这篇关于StringBuilder到字符串数组如何转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆