-1

How to Read character after '\':

string PrName = "software\Plan Mobile"; 
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
ashwin1014
  • 351
  • 1
  • 5
  • 18

3 Answers3

2

First of all, do not forget @:

 string PrName = @"software\Plan Mobile"; 

Next, if you want just the tail only (i.e. "Plan Mobile") then Substring will do:

 // if no '\' found, the entire string will be return
 string tail = PrName.Substring(PrName.IndexOf('\\') + 1);

If you want both (all parts), try Split:

 // parts[0] == "software"
 // parts[1] == "Plan Mobile"
 string[] parts = PrName.Split('\\');
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
0

Try this:

char charToFind = '\';
string PrName = "software\Plan Mobile";

int indexOfChar = PrName.IndexOf(charToFind);

if (indexOfChar >= 0)
{
    string result = PrName.Substring(indexOfChar + 1);
}

Output: result = "Plan Mobile"

pitersmx
  • 935
  • 8
  • 27
0

I think, you want to split string

   string s = "software\Plan Mobile";

   // Split string on '\'.
   string[] words = s.Split('\');

   foreach (string word in words)
   {
      Console.WriteLine(word);
   }

Output:

software
Plan mobile
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
Abdul
  • 2,002
  • 7
  • 31
  • 65