Removing line breaks in a string

Get help using Construct 2

Post » Fri Apr 06, 2012 3:19 am

Is there a way to remove line breaks from a string in C2?

For example: I'm importing text from a file using AJAX that looks like this:
name1|001|Dialog 1|
name1|002|Dialog 2|
name2|001|Dialog 3|

When it's saved to a string variable I want it to become this:
name1|001|Dialog 1|name1|002|Dialog 2|name2|001|Dialog 3|

I'm familiar with the "replace" system event but I don't know how to have it search for a linebreak. I tried newline and "/n" with no luck.

Thanks.

B
20
S
5
G
3
Posts: 65
Reputation: 3,764

Post » Fri Apr 06, 2012 3:49 am

newline

"name1|001|Dialog 1|" & newline & "name1|002|Dialog 2|" & newline & "name2|001|Dialog 3|"
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,129

Post » Fri Apr 06, 2012 4:24 am

Hes not tryin to add linebreaks hes tryin to remove em

I dunno if construct has a chr() expression but chr(10)+chr(13) is a newline. If nothin else you can try that
B
13
S
5
G
2
Posts: 306
Reputation: 3,262

Post » Fri Apr 06, 2012 10:03 pm

@aridale - No, it appears that C2 does not have a chr() function. Thanks, though.
B
20
S
5
G
3
Posts: 65
Reputation: 3,764

Post » Sun Apr 08, 2012 12:18 am

[code]set myText to replace(myText,newline,"")[/code]
works fine

Also in scripting language the linebreak is \n not /n
But yeah that doesn work with c2
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Apr 08, 2012 2:23 am

@Yann

Fantastic! I could have sworn I tried that, without success. But it's working now.
B
20
S
5
G
3
Posts: 65
Reputation: 3,764


Return to How do I....?

Who is online

Users browsing this forum: Governador, Radulepy, tarek2, Thelegendvinny and 25 guests