我不确定这是否正是您所需要的,但是它将逐步删除引用的部分…
String quote = "I say: "I have something to say, "It's better to burn out then fade away"" outloud...";if (quote.contains(""")) { while (quote.contains(""")) { int startIndex = quote.indexOf("""); int endIndex = quote.lastIndexOf("""); quote = quote.substring(startIndex + 1, endIndex); System.out.println(quote); }}
哪个输出…
I have something to say, "It's better to burn out then fade away"It's better to burn out then fade away
更新
我不知道这是不是在欺骗…
String quote = "I say: "I have something to say, "It's better to burn out then fade away"" outloud..."Just in case you don't believe me"";String[] split = quote.split(""");for (String value : split) { System.out.println(value);}
哪个输出…
I say: I have something to say, It's better to burn out then fade away outloud...Just in case you don't believe me
更新
好,假的
String#split
StringBuilder sb = new StringBuilder(quote.length());for (int index = 0; index < quote.length(); index++) { if (quote.charAt(index) == '"') { System.out.println(sb); sb.delete(0, sb.length()); } else { sb.append(quote.charAt(index)); }}
更新
好吧,这基本上是
split带有选择的假货…
String quote = "blah blah 123 "hello" 234 "world"";boolean quoteOpen = false;StringBuilder sb = new StringBuilder(quote.length());for (int index = 0; index < quote.length(); index++) { if (quote.charAt(index) == '"') { if (quoteOpen) { System.out.println("Quote: [" + sb.toString() + "]"); quoteOpen = false; sb.delete(0, sb.length()); } else { System.out.println("Text: [" + sb.toString() + "]"); sb.delete(0, sb.length()); quoteOpen = true; } } else { sb.append(quote.charAt(index)); }}if (sb.length() > 0) { if (quoteOpen) { System.out.println("Quote: [" + sb.toString() + "]"); } else { System.out.println("Text: [" + sb.toString() + "]"); }}
产生…
Text: [blah blah 123 ]Quote: [hello]Text: [ 234 ]Quote: [world]
知道,我不知道您如何存储结果。我很想创建一些能够存储
String结果并将其添加到a的基本类,
List以便我可以维持顺序,并可能使用某种类型的标志来确定它们是什么类型…
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)