C#/ASP.Net 中使用分隔符分割字符串
如果我这样做:
string text = "Hello, how are you?";
string[] split = text.Split('h', 'o');
如何获取每个拆分之间使用的分隔符的列表?我正在尝试重新创建整个字符串。
If I do this:
string text = "Hello, how are you?";
string[] split = text.Split('h', 'o');
How do I get a list of what delimiter was used between each split? I'm trying to recreate the string as a whole.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如@Davy8 提到的,没有内置的方式。这是一个非常简单的示例,可帮助您继续编写自定义方法。
As @Davy8 mentioned, there is no built in way. Here's a VERY simple example to get you going on writing a custom method.
据我所知,没有内置的方式。您最好编写自己的自定义拆分方法来跟踪分隔符。
There isn't a built in way that I'm aware of. You're probably better off writing your own custom split method that keeps track of the delimiters.
这是不可能的。字符串已被拆分,那么您如何知道拆分是基于“h”还是“o”?
无论如何,如果你能做到这一点:
那么为什么不存储这些字符呢?
This is impossible. The string has been split, so how can you possibly know if the split was based on a 'h' or an 'o'?
Anyways if you can do this:
then why not also store those characters?