[C#]在每个部分的开头拆分并保留分隔符 [英] [C#] Split and keep delimiters at the start of each sections

查看:103
本文介绍了[C#]在每个部分的开头拆分并保留分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我正在做ac#应用程序,我需要拆分用户输入。

Hi ! I'm doing a c# application and I need to split user inputs.

如果用户有类似"-push $ a 75 $ c 2 -wait $ t 100"之类的东西,输出应该是这个数组:[" -push $ a 75 $ c 2"," -wait $ t 10" ]。

If the user entre something like "-push $a 75 $c 2 -wait $t 100", the output should be this array : [ "-push $a 75 $c 2", "-wait $t 10" ].

并非我在数组中包含所有分隔符:[" -push"," -wait"," -cursor",...]

Not that I have all delimiters in an array : [ "-push", "-wait", "-cursor", ...]

我尝试搜索"拆分并保留分隔符c#"但是没有一个结果是好的。所以,如果有人想让我为它做一个小代码,我会很满意。

I tried searching "Split and keep delimiters c#" but none of the results were good.So, if somebody feels to make me a small code for it, I would be satisfied.

感谢阅读!

注意:我是法国人,抱歉我的英语不好> :(

Note : I'm french, sorry for my bad english >:(

推荐答案

你好,

这里有一个例子,< g class =" gr_ gr_37 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr -id =" 37" id =" 37"> splita< / g>使用分隔符的字符串,通过Select()LINQ投影方法将
附加到每个项目

here is an example that <g class="gr_ gr_37 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="37" id="37">splita</g> a string using a delimiter, which is appended to each item through the Select() LINQ projection method

public static List<string> splitAndKeepDelimiters(char delimiter, string str)
{
     return str.Split(delimiter).Select(s =>


" {delimiter} {s}");
}
"{delimiter}{s}"); }

但问题是如何处理参数值包含 分隔符!!!

but the question is how to deal with parameters values that contain the delimiter character!!!

例如:

-push


a 75


这篇关于[C#]在每个部分的开头拆分并保留分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆