How to split "enter" character in a string?

str = “test1”+environtment.newline+“test2”
arr_str = str.split(environtment.newline+“test2”.tochararray)
arr_str(0)

the result is still:
test1
test2

what i want is:
test1

Hi @wija

Str.split(" ".tochararray).first

try this once

space works as enter as well?
i will try first

@wija

Assign: arr_str = inputText.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

Hi @wija

Use the below split condition

=> Assign -> StrVar = "Test1"+Environment.NewLine+"Test2"
=> Assign -> Output = StrVar.Split(vbcrlf.ToCharArray).First

Check the below image for better understanding

Hope it helps!!

strD=strD.Split(
new string[ ] { Environment.NewLine },
StringSplitOptions.None)[0]

Hi @wija

input="test1"+Environment.NewLine+"test2"
output=input.Split(Environment.NewLine.ToCharArray).First

both input and output variables are of Datatype System.String

Hope it helps!!

can u try with this requirement inside the split?

environtment.newline+“test2”.tochararray

Hi,

Your expression seems no problem to return just “test1” as the following.

Can you share actual workflow (Screenshot or file)?

Regards,

Hi @wija

It will return tes1 as your output. Check the below image for better understanding.

Regards

@Yoichi

i don’t know, i try my expression in new blank project and seems nothing wrong & works the way i want.

but in my other project, using same code, it is not giving the value i want =_=
only (environment.newline.tochararray).first is giving value i want, while
(environment.newline+“the text”.tochararray).first is not giving value i want

i even use message box before split & after split to check the result, the result both message box are same nothing changed. so annoying

Hi,

environment.newline.tochararray returns char array : {chr(13), chr(10)} This split the string by chr(13) or chr(10)

On the other hand, environment.newline+“the text”.tochararray returns single string : "\r\nthe text" This split the string by the single string.
(note: \r is chr(13), \n is chr(10))

From the above point, Is here any reason to unable to split?

Regards,

hmm, based on this…
is there an idea to make it splitted as {“\r”, “\nthe text”}
?

The following will work. Can you tryy this?

yourString.Split({chr(13),chr(10)+"the text"},StringSplitOptions.RemoveEmptyEntries)

Regards,

this code won’t give exception error regardless any kind of string value in a string variable?
i mean, will this code become problematic in future?

Hi,

This expression returns one or more string item as string array.
So, it doen’t throw exception itself. However, as there might not be 2nd or more items, it might be caused by error if access 2nd item, in later process, for example.

Regards,

well, hmm
marked as solution then.
thank you.

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