Split String to Array

How do I split a string to array with the seperator being double NewLine?

The following code works, but then the seperator is only one NewLine.

String.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries)

I have tried the following, but i can’t seem to make it work.

TilbudText.Split({Environment.NewLine.ToArray,Environment.NewLine.ToArray}, StringSplitOptions.RemoveEmptyEntries)

Cheers!

1 Like

Hi @LarsFeilberg

Use String.split({Environment.newline},StringSplitOptions.None)
Check this
Thanks
Ashwin S

1 Like

Hi @AshwinS2

It doesen’t work. It prints nothing.
String.split({Environment.newline},StringSplitOptions.None)

Hi @LarsFeilberg
use String.Split("".ToCharArray)

Thanks
Ashwin S

1 Like

@LarsFeilberg Try this once String.Split((Environment.NewLine+Environment.NewLine).ToArray ,StringSplitOptions.RemoveEmptyEntries)

1 Like

Hej @inp

Just tried:
String.Split((Environment.NewLine+Environment.NewLine).ToArray ,StringSplitOptions.RemoveEmptyEntries)

This also only seems to seperate lines based on one NewLine.

1 Like

I got a string like this:

"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tincidunt vulputate nunc eu pellentesque. In tincidunt sit amet tellus sed mollis.

Aenean facilisis, ipsum sit amet lacinia congue, arcu magna mattis tortor, vitae mattis dui lorem id eros.
Vivamus vel odio id neque lacinia congue.
Donec id est ultrices, aliquet nibh a, venenatis elit.
Curabitur ultrices pellentesque sem, ac bla

Cras luctus suscipit mi sed suscipit. Ut sit amet orci efficitur erat consequat mollis ac non turpis. Duis placerat, nunc eget placerat lacinia,
velit sapien dignissim tortor, id congue tortor mauris sed erat. Nunc sed ex ultricies, hendrerit libero at, dapibus sem. Nullam egestas lorem non vehicula feugiat. Curabitur aliquet"

Then i want to divide this into an array with 3 string.

1 Like

Hi @LarsFeilberg

You can split the string based on String.Split("".toCharAray)

Thanks
Ashwin S

1 Like

Hey @AshwinS2

This doesn’t make my string split into 3 parts based on two NewLines. This makes my string split every time a space appears, which i am not interested in.

Hi @LarsFeilberg
Why do you need to split into multiple parts

Thanks
Ashwin S

Each section contains information about a customer, thus i need to divide each customer. The catch is that when i scrape the data, it comes out as 1 long string, and thus I need to split it into multiple parts. One part for each customer.

@LarsFeilberg

Use below code to split
for your requirements

system.Text.RegularExpressions.Regex.Split(YourInputStringVariable,"\n\s+")

1 Like

Hi Greetings!

use this code below in array variable. (text - input string)

split(text, Chr(10)+Chr(10))

We have the following newline representations in various .net frame works:

Chr(10)
Chr(13)
vbCr
vbLf
\n
\r
vbNewLine
Environment.Newline

Thanks!

1 Like

Please mark it as solution if it is working fine.

Hello @amaresan

It works like a charm!! Thank you - I much appreciate you taking the time to help me.

Cheers!

1 Like

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