Substring issue

Our Man in Bananas

I have the below code:

sDocType = pqReq.Substring(0, pqReq.IndexOf(@"\t"));

The string pqReq is like this: "CSTrlsEN\t001\t\\sgprt\Projects2\t001\tCSTrl". But even though I can clearly see the t\ in the string, pqReq.IndexOf(@"\t") returns -1, so an error is thrown.

What's the correct way to do this? I don't want to split the string pqReq until later on in the code.

Abbas

Use \\t instead of \t. The \t is seen as a tab-character. sDocType = pqReq.Substring(0, pqReq.IndexOf(@"\t"));

Edit:

I didn't notice the \t being literal due to the @. But is your input string a literal string? If not, place an @ before the value of pqReq.

string pqReq = @"CSTrlsEN\t001\t\\sgprt\Projects2\t001\tCSTrl";
int i = pqReq.IndexOf(@"\t");
//i = 8

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related