Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 15-Jul-12 23:46pm
v2

Please try it

VB
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);
	}
    }
}


Hope it helps
Sebastian
 
Share this answer
 
v2
Comments
JF2015 16-Jul-12 5:51am    
Nice! Although it is not VB.NET and does not completely solve the problem because of the last part of the string. 4+
Sebastian T Xavier 16-Jul-12 5:59am    
Thanks
Use split function and pass first parameter is your string and second one is underscore.
 
Share this answer
 
VB
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
 
Share this answer
 
Comments
johnjsm 16-Jul-12 7:43am    
Thanks. This worked perfectly.
JF2015 16-Jul-12 7:46am    
I'm glad that I could help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900