Jump to content

Recommended Posts

Posted

Have been unable to get my mind around this one even after studying string processing in Help. If a string contains CRLF CR and/or multiple spaces how do you replace these non typing characters with a single space.

For example what code would you use to change this text string:

Before :

'This is an example

of the text

to be fixed'

After:

'This is an example of the text to be fixed'

Help is always appreciated

Posted (edited)

@anixon

$delCRLF = StringReplace($s_string, @CRLF, ' ')
$delCR = StringReplace($delCRLF, @CR, ' ')
MsgBox(64, 'StringReplace', $delCR)

Not tested,

Cheers, FireFox.

Thanks for that works with cr and crlf what about if the text contains multiple spacing like test.....and this was..........the result. Please read the periods 'full stops' as spaces Ant.. Edited by anixon
Posted (edited)

Or maybe:

$str = @CR & "  This    is a   test  " & @CR & @CRLF & "   .  "
$str = StringStripWS($str ,7)
Msgbox(1,"",$str)

EDIT: Oops, typo

Edited by Spiff59
Posted

This is a combination of both codes that does the requested task. Thanks for your help.

CODE
$s_string = "This is test" & @crlf & "to see whats what" & @crlf & "whats what again"

$delCRLF = StringReplace($s_string, @CRLF, ' ')

$delCR = StringReplace($delCRLF, @CR, ' ')

$str = StringStripWS($delCR ,7)

Msgbox(1,"",$str)

Posted

This is a combination of both codes that does the requested task. Thanks for your help.

CODE
$s_string = "This is test" & @crlf & "to see whats what" & @crlf & "whats what again"

$delCRLF = StringReplace($s_string, @CRLF, ' ')

$delCR = StringReplace($delCRLF, @CR, ' ')

$str = StringStripWS($delCR ,7)

Msgbox(1,"",$str)

If you read the help file on StingStripWS, it by itself removes:

Chr(9) thru Chr(13) which are HorizontalTab, LineFeed, VerticalTab, FormFeed, CarriageReturn, the null string "" (Chr(0)) and the standard space " " (Chr(32))

Posted

$s_string = "This is test" & @crlf & "to see whats what" & @crlf & "whats what again"
$str = StringRegExpReplace ($s_string, "\s+", " ")
Msgbox(1,"",$str)

I'm getting better at this RegExp stuff me thinks! :)

Posted

$s_string = "This is test" & @crlf & "to see whats what" & @crlf & "whats what again"
$str = StringRegExpReplace ($s_string, "\s+", " ")
Msgbox(1,"",$str)

I'm getting better at this RegExp stuff me thinks! :)

You can say that again reducing a number of steps into a single line of code I am humbled by the experience Ant..

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...