Sign in to follow this  
Followers 0
gcue

stringregexp replace leading spaces of every line from edit control

7 posts in this topic

hello world..

i am trying to remove the leading spaces for every line in an edit control...

i was going to cycle through each line using _GuilCtrlEdit_GetLine and remove the spaces using stringstripws

but i think this can probably done faster using stringregexp

i found this.. '?do=embed' frameborder='0' data-embedContent>>but it doesnt seem to work when i replace the - with a $

its probably because the $ isnt being read as a literal character so i tried using chr(36) - still didnt work.

any ideas?

thanks in advance

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

here's a sample data set.

$string = "     $4 months" & @crlf

$string &= "       $until notice is due" & @crlf

$string & = "       $due date = 4/12/2015  " & @crlf

Edited by gcue

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$string = "     $4 months" & @crlf
$string &= "       $until notice is due" & @crlf
$string &= "       $due date = 4/12/2015  " & @crlf
ConsoleWrite($string)
$string = StringRegExpReplace($string,"(\h+)(.*)","$2")
ConsoleWrite($string)

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$string = "     $4 months" & @crlf
$string &= "       $until notice is due" & @crlf
$string &= "       $due date = 4/12/2015  " & @crlf

$Result = StringRegExpReplace($string, "(?:\n|\A)(\s)*", "")

msgbox(0, '' , $string)
msgbox(0, '' , $Result)

edit:  with OPs example rather than link

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

jdelaney - worked great!!

boththose - i think that strips trailing spaces for each line too

thank you very much for your help guys

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

nope:  the number, then the expected number of 32s (spaces), followed by a 13 (CR).  ** I am however stripping off line feeds..

#include <Array.au3>


$string = "      2  " & @crlf
$string &= "           3   " & @crlf
$string &= "       4    " & @crlf

$Result = StringRegExpReplace($string, "(?:\n|\A)(\s)*", "")

msgbox(0, '' , $string)
msgbox(0, '' , $Result)

_ArrayDisplay(StringToASCIIArray($result))

StringRegEx route leaving LF:

#include <Array.au3>

$string = "        2  " & @crlf
$string &= "           3  " & @crlf
$string &= "       4  " & @crlf

$aResult = StringRegExp($string, "(\H.*\s\n)"  , 3)

_ArrayDisplay(StringToASCIIArray(_ArrayToString($aResult , "")))
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

$string = "     $4 months" & @crlf
$string &= "       $until notice is due" & @crlf
$string &= "       $due date = 4/12/2015  " & @crlf
ConsoleWrite($string)
$string = StringRegExpReplace($string,"(?m)^\h+|\h+$", "")
ConsoleWrite($string)

Edited by jguinch

Share this post


Link to post
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
Sign in to follow this  
Followers 0