Jump to content

String Manipulation


anixon
 Share

Recommended Posts

Given the power of the '+' in this code how would you delete a tab CRLF Whitespace etc should it be present at the beginning of the text

$text = " This is an example of"

$sMessage = StringRegExpReplace($text, "\s+", " ")

Link to comment
Share on other sites

  • Moderators

Given the power of the '+' in this code how would you delete a tab CRLF Whitespace etc should it be present at the beginning of the text

$text = " This is an example of"

$sMessage = StringRegExpReplace($text, "\s+", " ")

StringRegExpReplace($s_string, "(?s)^(\s+)(.*?\z)", "\2")

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Sorry that does not quite work as it leaves in a carriage return Ant..

The carriage return is at the beginning?

If you're trying to get rid of all carriage returns, this will do it:

StringRegExpReplace($s_string, "[\r\n]+", "")

Or StringStripCR()

Or StringReplace($s_string, @CR, ""), StringReplace($s_string, @LF, "")

My code I posted would remove any space that started at the beginning of the string?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

The carriage return is at the beginning?

If you're trying to get rid of all carriage returns, this will do it:

StringRegExpReplace($s_string, "[\r\n]+", "")

Or StringStripCR()

Or StringReplace($s_string, @CR, ""), StringReplace($s_string, @LF, "")

My code I posted does remove any space that started at the beginning of the string?

Thanks for the reply the code I posted replaces everything that is applicable to to the \s+ flag with a " " space' with the exception that where the first character in the string is a space 'Whitespace?' it is not removed

$text = "This is an example

of A"

$text = " This is an example of B"

$sMessage = StringRegExpReplace($text, "\s+", " ")

The result would be as follows:

'This is an example A

' This is an example B

'This is an example A

' This is an example B

The use of the ' is so as to demonstrate that the text is not left justified because of the space

The desired result would all text left justified with single spaces between text and no carage returns as follows:

This is an example A

This is an example B

This is an example A

This is an example B

Ant..

Edited by anixon
Link to comment
Share on other sites

Problem resolved with this code

CODE

$Text = " This is a copy

of text with leading whitespaces and @CRLF"

$Txt = StringStripWS(StringRegExpReplace($text, "\s+", " "), 1)

Result: This is a copy of text with leading whitespaces and @CRLF"

Thanks to those who contributed to this thread... 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...