Jump to content
Sign in to follow this  
sambalec

Regex : How to remove white space before a string and after the string

Recommended Posts

sambalec

Hi !

How can I use StringRegExp to remove white space before a string and after the string ?

Example :

$var = " Testéà' - 123456 "

I need this result : $var2 = "Testéà' - 123456"

Many thanks. :-)

Sambalec

Share this post


Link to post
Share on other sites
Ramzes

Easier is using StringStripWS.

$var2 = StringStripWS($var, 3)
Edited by Ramzes

Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font]

Share this post


Link to post
Share on other sites
sambalec

Thanks a lot !!

Sambalec

Share this post


Link to post
Share on other sites
sambalec

Another problem :

$test = StringStripWS(" Enghien les bains ",3)

MsgBox(0,"result",$test)

It doesn't work with this example, the result is " Enghien les bains " but I need "Enghien les bains" (without first and last whitespace)

Can you try for me ?

Thanks :graduated:

Sambalec

Share this post


Link to post
Share on other sites
sambalec

I think its a big bug ... maybe encoding ...

Can I remove the 1st and the last caracter with a special func ?

Thanks

EDIT : StringTrimLeft is perfect for me

Sambalec

Edited by sambalec

Share this post


Link to post
Share on other sites
Ramzes

I don't know. It's working for me too.

$String = StringStripWS(" Hello there!  ", 3)
MsgBox(0, "Test", "|" & $String & "|")

If it doesn't work (I don't understand why) you must use StringTrimLeft and StringTrimRight.


Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font]

Share this post


Link to post
Share on other sites
jchd

I think its a big bug ... maybe encoding ...

I don't believe so! Can you post a very short script to replicate the issue?

Bonne baignade en tous cas !


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
czardas

Did you run the script I posted? When I run the code, it gives me a message box saying the string contains 17 characters. Realize that spaces are characters and also form part of the string. If you got a message box saying the string contains 19 characters, then I will believe you.

Edited by czardas

Share this post


Link to post
Share on other sites
Yashied

I think its a big bug ... maybe encoding ...

Are you sure that this is a whitespaces, and not any other characters? For example:

$test = StringStripWS(ChrW(160) & "Enghien les bains" & ChrW(160), 3)
ConsoleWrite($test & @CR)
Edited by Yashied

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  

×