分裂()的字符串到字符串数组,并没有得到一个空白[0] [英] split() a String to a Stringarray, and not getting a blank at [0]

查看:152
本文介绍了分裂()的字符串到字符串数组,并没有得到一个空白[0]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图分裂()的字符串,没有空格,但得到一个空白[0]

 一个String =..1..3 ..;
的String [] = RESULT2 s.split();
的System.out.println(结果2 [0]); //给我一个空白

我心中已经意识到未必是正确的,但不能找到一个替代品。是否有可能分裂别的东西,或采用分体式()这样的时候我会永远得到这个空白?

编辑答案:

  StringBuilder的响应=新的StringBuilder();
     而((ⅰ= in.read())!= - 1){
            response.append((char)的一);
     }
     结果= response.toString();
     结果= result.replace(\\ n,).replace(\\ R,);


解决方案

  • 0 包含字符串的第一个点(即空字符串)
  • 开始的数据
  • 1 包含的第一个点

  • 2 包含第二点

  • 3 包含字符串 1

  • ...

I'm trying to split() a String with no whitespaces, but getting a blank at [0].

String s = "..1..3..";
String[] result2 = s.split("");
System.out.println(result2[0]); // giving me a blank space

I'v realized that "" might not be the right one, but cant find a alternative. Is it possible to split on something else, or will I always get this whitespace when using split() this way?

EDIT SOLUTION:

     StringBuilder response = new StringBuilder();
     while((i = in.read()) != -1){     
            response.append((char)i);  
     }
     result = response.toString();   
     result = result.replace("\n", "").replace("\r", "");

解决方案

  • 0 contains the data from the beginning of the string to the first dot (i.e. an empty string)
  • 1 contains the first dot
  • 2 contains the second dot
  • 3 contains the string 1
  • ...

这篇关于分裂()的字符串到字符串数组,并没有得到一个空白[0]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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