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
Get a string after a symbol
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Blocked AccountRank #403 · 6.2K reputationPosted Mar 7, 2013, 11:07 PM EST
string s = "darma-Teja";
int dash = s.LastIndexOf("-");
string s1 = s.Substring(dash + 1, s.Length - (dash + 1));
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 7, 2013, 11:06 PM EST
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());
}
}
}
Sreejesh SPRank #1,975 · 740 reputationPosted Mar 7, 2013, 11:08 PM EST
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