Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi all,
I am working on spliting of string. I want to split a string into words and show all those word into a textbox. How could I do that?
neaS
Posted
Updated 5-Sep-11 21:03pm
v2

C#
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);
	}
    }
}


Output

there
is
a
cat
 
Share this answer
 
v3
 
Share this answer
 
VB
Imports System.Text.RegularExpressions
Private Function SplitWords(ByVal s As String) As String()
        Return Regex.Split(s, "\s+") 
End Function

VB
Dim parts as String()="abc,pqr"
words = parts.Split(",")

it will split string in words on the comma ',' basis...
 
Share this answer
 
v2

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