Sign in to follow this  
Followers 0
gcue

strip out letters from a string

7 posts in this topic

hello.

i am trying to do this using stringregexp but don't understand why only 1 character returns in the array

#include <array.au3>

$string = "AbC12D22"

$string = StringUpper($string)
$new = StringRegExp($string, "[A-Z]", 1)

_ArrayDisplay($new)

Share this post


Link to post
Share on other sites



Because you set the flag to 1 - use 3 but also change search pattern to "(?i)[a-z]".

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

ahhh.. nice! which there was an option to return a string instead of an array.. hassle to go through that array to string conversion

Share this post


Link to post
Share on other sites

You have to invers the search pattern:

#include <array.au3>

$string = "AbC12D22"

$string = StringUpper($string)
$new = StringRegExp($string, "(?i)[a-z]", 3)
_ArrayDisplay($new)
$snew = StringRegExpReplace($string, "(?i)[\d]", "$1")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $snew = ' & $snew & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Strip letters or numbers from string?

$string = "AbC12D22"

$new = StringRegExpReplace($string, "[0-9]", "")   ; Reslts in $new = "AbCD"
MsgBox(0,"Result",$New) ;

$new = StringRegExpReplace($string, "[^0-9]", "") ; Reslts in $new = "1222"
MsgBox(0,"Result",$New) ;

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

ahh makes sense.. many thanks UEZ!

Share this post


Link to post
Share on other sites

nice simple method bowmore =)

thanks!

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