Hi everybody, I need a little help regarding string. I want to break the string. The example is given following.
STRING: AL HAMZA SHIP BREAKING CO
INTO:
AL
HAMZA
SHIP
BREAKING
CO
Please send me the code for breaking the sentance.
Regards
Zeb
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question.
VulpesPosted Dec 7, 2011, 6:15 AM
If you don't do this, then the array produced by String.Split will contain an empty string for each surplus space.
Sam HobbsPosted Dec 8, 2011, 11:03 PM
Zeb RehmanPosted Dec 8, 2011, 2:50 PM
Zeb RehmanPosted Dec 8, 2011, 2:49 PM
Pravin MorePosted Dec 7, 2011, 5:52 AM
use like this.....
string strsplit = "my name is Zeb";
string[] lines = strsplit.Split(new string[] { " ", "\n" }, StringSplitOptions.None);
MessageBox.Show(lines[0].ToString()); //will give "my"
thanks,
Pravin.
Satyapriya NayakPosted Dec 7, 2011, 5:41 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = "AL HAMZA SHIP BREAKING CO";
string[] words = s.Split(' ');
foreach (string word in words)
{
Console.WriteLine(word);
}
Console.ReadLine();
}
}
}
Thanks