2/20/2023 0 Comments Nul stx etx![]() ![]() You might consider using a Trim() to trim any excess spaces ( m.()). String pattern = (string input in inputs)įoreach(Match m in Regex.Matches(input, pattern)) "dksldkls some string 4.1ds ds some string 4.2 jdskjd" Since your last example has multiple occurrences you can use the Matches method. Remove the ? and you'll see what I mean in your str4 example. By being non-greedy it prevents the regex engine from greedily matching multiple occurrences and content till the last "" occurrence. The (. ?) is a capturing group (due to the parentheses) and matches at least one character in a non-greedy fashion (via the ?). Notice that the opening bracket, need not be escaped. By doing so you no longer need to use Trim() as I suggested in my earlier response below. I also added the \s* between the grouping to eliminate extra whitespace. String pattern = m in Regex.Matches(input, pattern)) New RegEx which will extract data betweenĪs means a transmission has been started so i want to extract data between STX as well.ĮDIT: to fit your updated requirements you should use this pattern that takes advantage of look-arounds to skip all STX groups except the last one that has an ETX after it: string pattern = a complete example: string input = string 1ĭksldkls some string 4.1ds ds some string 4.2 jdskjd If i want the data between and also can that also be done. The real problem comes when followed by i want to consider the newer and start string processing from the newer occurance. The above string can be " djkdsj dskd2 ddd" The above string can be " kdsj dskd1 dsnds" The above string can be " djkdsj dskd1 ddd" The above string can be " djkdsj dskd1 dsnds" How can i get the same output if the string array is one single string /* output */ dksldkls some string 3 ds dsĭksldkls some string 4.1ds ds some string 4.2 jdskjd" * Append Output To a TextBox or Append it to a String using For Loop.*/ * The output after passing these to a ProcessString () */ What To Write here using RegEX or String Functions in c# ProcessString (string str, string startparam, string endparam) String using string builder or treat them as different strings*/ * the various strings can be appended and converted to a single String str4 = "dksldkls some string 4.1ds ds some string 4.2 jdskjd" //Option 4 String str3 = " dksldkls some string 3 ds ds" //Option 3 String str2 = "sajksajsk some string 2 saksla" //Option 2 Anything that is between and must be accepted rest of the things must be rejected. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |