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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Feb 16, 2010, 8:01 PM EST
string Data = "Welcome or";
string[] SplitedString = Data.Split(' ');
//Access Only Second Item
string SecondWord = SplitedString[1];
MessageBox.Show(SecondWord);
Diptimaya PatraRank #113 · 19.8K reputationPosted Feb 16, 2010, 4:47 PM EST
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
kiran kumarRank #3,110 · 461 reputationPosted Feb 16, 2010, 4:50 PM EST
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
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Feb 16, 2010, 7:20 PM EST
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
Lalit MRank #1,186 · 1.5K reputationPosted Feb 16, 2010, 8:53 PM EST