将字符串分割成几部分 [英] Split string into parts

查看:62
本文介绍了将字符串分割成几部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要通过以下方式拆分文本字符串

原文:John_Liz_Today_99_Finished_Weekday



约翰
丽兹
今天
99
Finished_Weekday

任何帮助都很好

谢谢
J

Hi,
I need to split a text string in the following way

Original: John_Liz_Today_99_Finished_Weekday

to

John
Liz
Today
99
Finished_Weekday

Any help would be great

Thanks
J

推荐答案

请尝试

Please try it

using System;

class Program
{
    static void Main()
    {
	string s = "there is a cat";
	//
	// Split string on spaces.
	// ... This will separate all the words.
	//
	string[] words = s.Split('-');
	foreach (string word in words)
	{
	    Console.WriteLine(word);
	}
    }
}



希望对您有帮助
Sebastian



Hope it helps
Sebastian


使用拆分功能并传递第一个参数是您的字符串,第二个参数是下划线.
Use split function and pass first parameter is your string and second one is underscore.


Dim test As String = "John_Liz_Today_99_Finished_Weekday"
Dim parts As String() = test.Split("_"C)
If parts.Length >= 6 Then
    MessageBox.Show(parts(0))
    MessageBox.Show(parts(1))
    MessageBox.Show(parts(2))
    MessageBox.Show(parts(3))
    MessageBox.Show(parts(4) & "_" & parts(5))
End If


这篇关于将字符串分割成几部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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