本文介绍了如何使用嵌入式双引号解析字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个类似于以下内容的字符串: " MyString 40Hello world所有 它包含空格,可能是空格或制表符,或者是一个组合,我想要生成一个包含以下元素的数组 arr(0)=" MyString" arr(1)= 40 arr(2)=" Hello world" arr(3)=" all" 使用修剪和正则表达式(\s +),我可以将我的字符串减少到 " MyString 40" Hello world"所有 和Split我可以得到 arr(0)=" MyString" arr (1)= 40 arr(2)="" Hello" arr(3)=" world"" arr(4)=" all" 正如你所看到的,它不是我需要的。 Hello world 中的空格已减少到单个空格,而Split不会尊重双重引号,并将Hello world分割为Hello world。超过两个元素。 有谁知道我该怎么做?我可以按字符处理字符串 ,但是我希望有一个直接的 技术来做,没有循环,并使用一些技术我已经拥有了。 TIA CharlesI have a string similar to the following:" MyString 40 "Hello world" all "It contains white space that may be spaces or tabs, or a combination, and Iwant to produce an array with the following elementsarr(0) = "MyString"arr(1) = 40arr(2) = "Hello world"arr(3) = "all"Using trim and a regular expression ("\s+"), I can reduce my string to"MyString 40 "Hello world" all"and with Split I can getarr(0) = "MyString"arr(1) = 40arr(2) = ""Hello"arr(3) = "world""arr(4) = "all"As you can see, it is not quite what I need. The spaces in "Hello world"have been reduced to a single space, and Split does not respect the doublequotes, and splits "Hello world" over two elements.Does anyone have an idea how I could do this? I could process the stringcharacter by character, but I am hoping that there is a straight-forwardtechnique for doing it, without looping, and using some of the techniques Ialready have.TIACharles推荐答案 这篇关于如何使用嵌入式双引号解析字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 07:54