Crop string from start to substring C #

I am having trouble shortening my line. I have a windows forms application that accepts incoming data. So far, the examples I have found use char to search. I need him to look for the whole "*S" , and not just his one character.

I found a way to get the bite and trim index from this point to the end (sting.remove). My problem: I need to trim the beginning. so the cropping and indexing method will work, but I have not found how to do this.

I have a bunch of data like

 "ok \r\n *S 38773 get 3042" 

What I need to do is find *S and remove everything from the beginning to the *S Since the return is not always the same, I cannot use replacement or removal methods. I can not predict what will happen before * S, and the rest of the data will be dynamic.

Any examples of how to substantially trim the beginning of "* S" would be great. Thanks.

+4
source share
2 answers
 string huh = "ok \r\n *S 38773 get 3042"; string trimmed = huh.Substring(huh.IndexOf("*S")); 
+5
source
 s = s.Substring(s.IndexOf("*S")); 
+9
source

Source: https://habr.com/ru/post/1387079/


All Articles