-1

I'm working on a Existing Class file(.cs) which fetches a string with some data in it. I need to check if the string contains a word. String has no blank spaces in it.

The string-

"<t>StartTxn</t><l>0</l><s>0</s><u>1</u><r>0</r><g>1</g><t>ReleaseUserAuthPending</t>"

I need to check if the string contains 'ReleaseUserAuthPending' in it.

1
  • Use .Contains() or a regex Commented Aug 8, 2017 at 6:21

3 Answers 3

1

You can try this:

var strValue = "<t>StartTxn</t><l>0</l><s>0</s><u>1</u><r>0</r><g>1</g><t>ReleaseUserAuthPending</t>";
if (strValue.Contains("ReleaseUserAuthPending"))
{
    //Do stuff
}

Refer About String - Contains function

For your information: Contains function is case-sensitive. If you want to make this Contains function as case-insensitive. Do the following step from this link.

Sign up to request clarification or add additional context in comments.

Comments

0
bool containsString = mystring.Contains("ReleaseUserAuthPending");

2 Comments

It would be better to explain why this is the correct answer, not just provide some code.
It's not self documenting enough for you?
0

Try

String yourString = "<t>StartTxn</t><l>0</l><s>0</s><u>1</u><r>0</r><g>1</g><t>ReleaseUserAuthPending</t>";
if(yourString.Contains("ReleaseUserAuthPending")){
      //contains ReleaseUserAuthPending
}else{
     //does not contain ReleaseUserAuthPending
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.