[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - Removing line feeds/breaks from a string

Removing line feeds/breaks from a string

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Removing line feeds/breaks from a string

Postby PureMoxie » Fri Jun 30, 2006 5:03 am

Is there any way to remove line breaks from a string? I tried SubStrings with "\r\n" but that didn't work.

Thanks!
PureMoxie
New Arrival
 
Posts: 3
Joined: Wed Sep 22, 2004 4:03 pm

Postby MarkB » Sat Jul 01, 2006 12:28 am

Here's something.
Code: Select all
AddStrings $text "One" "\n" "two" "\n\n\n" "three"
MessageBox $text
:Loop
   StringPos #p "\n" $text
   If #p = 0 Then ExitLoop
   SubStrings $text "\n"
GoTo Loop
:ExitLoop
MessageBox $text
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby MarkB » Sat Jul 01, 2006 1:13 am

If you want spaces, you could try something like this:
Code: Select all
{ Replace newlines with spaces
{ PocoScript v3 (v4 might have a command for this)
{ MarkB, 2006-07

AddStrings $string "One" "\n" "two" "\n\n\n" "three" "\n\n\n\n" "four"
MessageBox $string

{ Reduce multiple newlines to single newlines
Set $substring "\n\n"
Set $replacement "\n"
Call StringReplace
{ Replace newlines with spaces
Set $substring "\n"
Set $replacement " "
Call StringReplace

MessageBox $string


:StringReplace
:Loop
   StringPos #p $substring $string
   If #p = 0 Then ExitLoop
   SubStrings $string $substring
   InsertString $string #p $replacement
GoTo Loop
:ExitLoop
Return
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby PureMoxie » Mon Jul 03, 2006 4:04 am

Thanks, Mark, those work fine. I don't know why I didn't think to just use \n instead of \r\n.
PureMoxie
New Arrival
 
Posts: 3
Joined: Wed Sep 22, 2004 4:03 pm


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 2 guests

cron