Jump to content

String Replace


anixon
 Share

Recommended Posts

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

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

$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! :)

Link to comment
Share on other sites

$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..
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...