Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to find out the if string in between contain '\' sign or not in c#


Please share your informations
Posted
Comments
Sergey Alexandrovich Kryukov 7-Aug-13 3:00am    
This is not "sign", this is character.
What do you mean "in between"? Not at the end or beginning? Or just somewhere in the string?
And http://whathaveyoutried.com?
—SA
OPees 7-Aug-13 5:37am    
use .Contains Method of string...

use either IndexOf or Contains method of string like
C#
string s = @"abc\12345";
int x= s.IndexOf('\\');
int y=x;
bool x1 = s.Contains('\\');
bool y1 = x1;
 
Share this answer
 
C#
string input = "abcd\cdef\efg\ijk\lmn";
 
string[] splitString = input.split('\');
 
string result = splitString[0].Trim();


Hope it will help..
 
Share this answer
 
Please see my comment to the question.

Now, all you need is this:
http://msdn.microsoft.com/en-us/library/system.string.aspx[^],
or perhaps this: http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx[^].

That's all.

…or no, that's not all. There is one thing you need a lot more: Microsoft Q209354.

Good luck,
—SA
 
Share this answer
 
C#
string your_String = "[StringValue]";

if (your_String.IndexOf('\\') >= 0)
{
   // String Contains '\' sign
}
else
{
  // String Does not Contain '\' sign
}
 
Share this answer
 
String.IndexOf[^]
C#
string str = "Some text";
if (str.IndexOf('\\') != -1)
{
   Console.WriteLine("Contains backslash.");
}
else
{
   Console.WriteLine("Does not contain backslash.");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900