Find four digits and add new line before them

Hi,

I have an interesting task

I have a string that is like below

1980 mlkasdak asdlad masdlm md dm 2020 laksd namsd 1975 njasdna sdand

I want the result to be

1980 mlkasdak asdlad masdlm md dm
2020 laksd namsd
1975 njasdna sdand

What is correct way to do it?

Hi,

How about the following?

String.Join(vbCrLf,System.Text.RegularExpressions.Regex.Split(yourString,"\s(?=\d{4})"))

Regards,

You could also use Regex.Replace():

newString = System.Text.RegularExpressions.Regex.Replace(inputString, " (?=\d{4})", Environment.NewLine)

Check this below workflow, @Anders_Dahl1
StringManipulation.xaml (5.1 KB)
Hope this may help you :slight_smile:

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