Splitting a string into array by # and []

Is there any code that is able to split a string based on given symbols, to determine the count of the sub strings, instead of using multiple splits?

e.g.
a [b] # c
a
b
c

This is the string [This is the bracketed string] # This is the string after, hash

in the above case, splitting by # and

sub strings:
This is the string
This is the bracketed string
This is the string after, hash

System.Text.RegularExpressions.Regex.Split(str_s,“[^\w\s]+,”).Where(Function(s) not String.IsNullOrWhiteSpace(s)).ToArray()

the above code splits all special characters, which results in the below, which is not correct
This is the string
This is the bracketed string
This is the string after
hash

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Split(yourString,"[#\[\]]").Where(Function(s) not String.IsNullOrWhiteSpace(s)).ToArray()

Regards,

what about if need to split by a word “MDM.” too?

How about the following?

System.Text.RegularExpressions.Regex.Split(yourString,"[#\[\]]|MDM").Where(Function(s) not String.IsNullOrWhiteSpace(s)).ToArray()

Regards,

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.