簡體   English   中英

如何在逗號處分割字符串但保留空格?

[英]How to split string at comma but keep white spaces?

如何在逗號處分割字符串,以便保留所有空格。 例:

Input: ["  hello  , world  "]

需要將其分隔成數組,使其看起來像這樣:

Array[0] = "  hello  "
Array[1] = " world  "

在連接它們之后:

Output: "  hello   world  "

嘗試使用split這樣的輸入法: input.split("\\\\s*,\\\\s*"))但隨后我將其分離而沒有空格...

Array[0] = "hello"
Array[1] = "world"

任何想法如何做到這一點?

    String s = " hello , world ";
    String s1[] = s.split(",");
    System.out.println(s1[0]+s1[1]);

   output:  hello  world 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM