Manipulate text file

I have a text file with numbers in each line.
But I need to fix it so that it’s all in one line separated by semi-colons. What the best way to achieve this?

.txt:

123
456
756

need result:
123; 456; 756

Thanks

What about using Replace?

text.Trim.Replace(System.Environment.Newline(0), "; ")
or
text.Trim.Replace(vblf(0), "; ")

You can also use Split but to join it back you also need String.Join

String.Join("; ", text.Trim.Split(System.Environment.Newline(0)) )
or
String.Join("; ", text.Trim.Split(vblf(0)) )

Regards.

1 Like

Thanks for your reply! This is a new way for me to see it! I’ve just tried it, it didn’t work though… so what I did was

  1. Read text and output string test
  2. Assign the string test2 as you mentioned above
  3. messagebox still shows me the item for every new line…

Any idea?
Thanks!

1 Like

To clarify, here is an example similar to what you are showing:

Read text file to variable test
Assign test2 = test.Trim.Replace(System.Environment.Newline(0), "; ")
Message box test2

You might also need to use vblf(0) instead of System.Environment.Newline(0)

Is this what you are doing? If so and it’s still not workign, then I’m not sure what could be the problem. Maybe if you can provide some screenshots of your workflow/properties or upload files, I can identify a solution better.

Regards.

Hi @ClaytonM,

Sure! Here is what I did:

image

image

image

I tried all the codes that you mentioned above for “Assign” and they all give the same result.
Any idea or solution?

Thanks!

Best regards,
Lavina

@lavint You don’t need the “(0)” at the end of Environment.Newline. Remove that and the existing code you have should work.

ToOneLine.xaml (5.4 KB)

1 Like

Works! Thank you!