分号后如何分裂刺痛 [英] How to split the sting after semicolon

查看:96
本文介绍了分号后如何分裂刺痛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

字符串a = 1,23,45; 6,7,8



i希望在半冒号后拆分字符串



我希望输出为关闭



1,23,45

6,7,8





这个怎么做csharp。



我尝试过:



string a = 1,23,45; 6,7,8



i希望在半冒号后拆分字符串



我希望输出为关闭



1,23,45

6,7,8





如何做csharp

string a = 1,23,45; 6,7,8

i want to split the string after semi colon

I want the output as follows

1,23,45
6,7,8


for that how to do in csharp.

What I have tried:

string a = 1,23,45; 6,7,8

i want to split the string after semi colon

I want the output as follows

1,23,45
6,7,8


for that how to do in csharp

推荐答案

1。您忘记了引号

1. You've forgotten quotes
string a = "1,23,45; 6,7,8";





2.如果你想要问题标题中提到的用分号分割字符串,你可以使用 String.Split [ ^ ]如下。结果是字符串数组



2. If you want split string by a semicolon as mentioned in the question caption you can use String.Split[^] as follows. The result is array of strings

var splitted = a.Split(';');





3 。如果您想要输出有问题,可以使用 String.Replace [ ^ ]



3. If you want output as in question you can use String.Replace[^]

var replaced = a.Replace(";", Environment.NewLine);


查找字符串。拆分方法。文档有一个很好的例子。
Look up the "String.Split" method. The documentation has a nice example.


参见如何:使用String.Split解析字符串(C#指南)| Microsoft Docs [ ^ ]:

See How to: Parse Strings Using String.Split (C# Guide) | Microsoft Docs[^]:
string[] splitted = a.Split(';');
foreach (var part in splitted)
{
    System.Console.WriteLine(


这篇关于分号后如何分裂刺痛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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