I want to get the second word of the sentence,for example if I type "Welcome or"
it displays only "or". How to do that? thanx ;)
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Feb 17, 2010, 1:01 AM
string Data = "Welcome or";
string[] SplitedString = Data.Split(' ');
//Access Only Second Item
string SecondWord = SplitedString[1];
MessageBox.Show(SecondWord);
Lalit MPosted Feb 17, 2010, 1:53 AM
Hirendra SisodiyaPosted Feb 17, 2010, 12:20 AM
Dim Sentance As String
Dim secondWord As String
Dim strArr() As String = Sentance.Split(" ")
If strArr.Length > 1 Then
secondWord = strArr(1)
End If
Thank you
kiran kumarPosted Feb 16, 2010, 9:50 PM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace stringsplit
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string s = "Welcome or";
string[]words=s.Split(' ');
foreach (string word in words)
{
if (word == "or")
{
textBox1.Text = word;
}
}
}
}
}
check the answer if it helps you
Diptimaya PatraPosted Feb 16, 2010, 9:47 PM
string givenText = "Welcome or";
string[] words = givenText.Split(' ');
for each(string item in words)
{
Console.WriteLine(item);
}
Try it.
Thanks
Diptimaya Patra
--------------------------------
MARK IT AS ANSWER IF IT HELPS