如何在字符串数组中为分号后指定拆分字符串?

编程入门 行业动态 更新时间:2024-10-26 04:26:30
本文介绍了如何在字符串数组中为分号后指定拆分字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

string [] Query = query.Split(';');我正在使用这个用于拆分string.i想要在semicolon.i之前的分割字符的semicolon.given代码之后如何拆分以及分号之后的代码。

解决方案

如果你想分开单词;在这之后接受这个词; 这样做 例如:字符串查询=xxx; yyy string [] Query = query.Split(';'); 查询[0]将是xxx 查询[1]将是yyy

你不能使用string.Split在一个字符后拆分 - 它在一个字符上拆分一个字符串:所以它删除了拆分指示符,并返回两个(或更多)不包含拆分的字符串性格。正则表达式也做同样的事情,但可以应对更复杂的匹配模式,所以他们赢了; t帮助你。 你可以做三件事: 1)编写自己的拆分方法,不删除拆分字符。 2)使用拆分,然后将拆分字符添加回每行后面。 3)使用String.Replace在每个分号后添加一个特殊字符,然后拆分。 第二个选项可能由于创建的字符串数量加倍,效率最低。

string[] Query = query.Split(';'); i am using this for for split string.i want code for how i split after semicolon.given code for split character in before semicolon.i want code for after semicolon.

解决方案

If you want to split the word from ; and take the word after the ; do like this Eg: string query = "xxx;yyy" string[] Query = query.Split(';'); Query [0] will be xxx Query [1] will be yyy

You can't use string.Split to split after a character - it splits a string on a character: so it remove the split indicator, and returns two (or more) strings which do not contain the split character at all. Regular expressions also do the same thing, but can cope with a more complex matching pattern, so they won;t help you either. There are three things you can do: 1) Write your own split method with does not remove the split character. 2) Use Split, and then add the split character back into each line afterwards. 3) Use String.Replace to add a "special character" after each semicolon, then split on that. The second option would probably be the least efficient as the number of strings created is doubled.

更多推荐

如何在字符串数组中为分号后指定拆分字符串?

本文发布于:2023-10-27 02:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532085.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   分号   数组   中为   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!