Extract a string using split, with strings as a delimiter

I need to extract “rhitam deb”
from the string below, using split function and there is a new line in the string too…
“Prepared By rhitam deb
Quote Number 00000008”

Rhitam Deb


You should just use a Regex pattern. Regex is in the namespace System.Text.RegularExpressions
Here is an example:

pattern = "(?<=(Prepared By))(.*)"
Regex.Match(str, pattern).Value.Trim

(.*) is a wildcard and will extract the match up to a newline and stop. (?<=( )) means that it will look for that string and extract anything after it.

If you still want to use the Split method, then I think it will look like this:

str.Split({"Prepared By"}, System.StringSplitOptions.None)(1).Split({"Quote Number"},System.StringSplitOptions.None)(0).Trim


1 Like

what is the datatype for pattern?
Is it a string?

Yeah, it’s a string.

There are various ways to set up a Regex function, but that’s just the simple way. For more examples, do some online searches in .net language syntax.

I am trying to split " 109 Master Bedroom" to “Master Bedroom”. Please provide with a solution

Hello @Rupendankhara
Use this this
Where strr is a string variable containing that particular string

1 Like

Got to try this

I would probably suggest splitting by the space if the “109” value can be different. Splitting by “109” will only work if it is always that value. Also, always add .Trim to remove the end spaces.

If you split by the space, it will create an array. Then, you can use .Skip and String.Join to combine the values back together. It would be like this:
String.Join( " ", strr.Trim.Split(" "c).Skip(1) )

Another option would be to use Regex, but this takes some time to learn. The solution for that off the top of my head without any testing might look like this:
System.Text.RegularExpressions.Regex.Match( strr.Trim, "(?<=([0-9]{1,6}))(.*)" ).Trim
It looks for the numbers, and pulls out everything after it.



I am not a programmer as you would guess. Please give the expression for string operations without regex.

@Rupendankhara see previous post. :smiley:
It splits by the space 'c’haracter and skips the first value.


Yes i understand that, but when i tryed to print the remaining of words, as its an array of string i have to mention all the words in the TITLE. For example. It could be"102 game room"or it also could be “203 master Hvac control room”

Yeah, I understand. The solution I presented will pull out “game room” and “master Hvac control room” as you require. Let me know if there is a mistake and if there are any errors, and I can help resolve them.


I will try it then


With few modification in the expression it works perfect. Thank you so much.

Appreciate you help.

1 Like