Hi,
I have a string like "darma-Teja" or "abc-d"
I wanted to get only Teja or d from the string.
It means whatever string I have after - symbol, I want as final output.
Thanks allot
Darma
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.
Blocked AccountPosted Mar 8, 2013, 4:07 AM
string s = "darma-Teja";
int dash = s.LastIndexOf("-");
string s1 = s.Substring(dash + 1, s.Length - (dash + 1));
Sreejesh SPPosted Mar 8, 2013, 4:08 AM
You have to use split function,
That is
string str="darma-Teja";
string[] str1=str.split('-');
string str2=str1[0];
the string str2 include "darma'"
next example is
string str="abc-d"
string[] str1=str.split('-');
string str2=str1[1];
the string str2 include "d"
please try this code
Thanks
Sreejesh
Satyapriya NayakPosted Mar 8, 2013, 4:06 AM
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string s1 = textBox1.Text;
string[] parts = s1.Split('-');
MessageBox.Show(parts[1].ToString());
}
}
}