cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

In ACL language, how to remove line breaks in a characters string

dgopois
13-Aquamarine

In ACL language, how to remove line breaks in a characters string

In ACL language, how to remove line breaks in a characters string?

I try this command:

gsub("\r\n", "", $x);

But it doesn't work.

Can you help me?

ACCEPTED SOLUTION

Accepted Solutions
dgopois
13-Aquamarine
(To:dgopois)

The PTC technical support has solved the problem, see below.

The first parameter to the gsub() function is a regular expression string and that does not support C syntax like \r and \n for carriage return and line feed. Instead you would have to put that string in a variable and then use the variable as the parameter to the function.

$s = "\r\n";
gsub($s, ' ', $x);

Or you could take if further with the following:
$s = "one\r\ntwo"
gsub("\r\n", "x", $s)

If instead your string only has a \r or \n then the character class

gsub("[\r\n]", "x", $s)

would work. The first regular expression matches two characters whereas the second matches only one. The first result would have one 'x' but the second would have 'xx'.

View solution in original post

4 REPLIES 4

I believe what you are looking for is chop($st,[int])

This is like the Perl func and removes the number of chars specified by [int] from $st. The integer is optional, default is 1 character, which is very useful for dropping the newline chars.

Are you sure that you're getting a match? Set your gsub function to a variable and test the result. If the result is 0, then no matches were found in the string. Otherwise, it returns the number of matches that it found.

You might have better luck if you just search for "\n".

dgopois
13-Aquamarine
(To:dgopois)

The PTC technical support has solved the problem, see below.

The first parameter to the gsub() function is a regular expression string and that does not support C syntax like \r and \n for carriage return and line feed. Instead you would have to put that string in a variable and then use the variable as the parameter to the function.

$s = "\r\n";
gsub($s, ' ', $x);

Or you could take if further with the following:
$s = "one\r\ntwo"
gsub("\r\n", "x", $s)

If instead your string only has a \r or \n then the character class

gsub("[\r\n]", "x", $s)

would work. The first regular expression matches two characters whereas the second matches only one. The first result would have one 'x' but the second would have 'xx'.

Announcements

Top Tags