Jump to content
Sign in to follow this  
michaelslamet

How to split contain from a string ??

Recommended Posts

michaelslamet

I have a field that is a memo type, contain phone number(s).

This field can contain only 1 phone number or more than 1 phone number separated by either "/" character, newline (@CRLF) and/or "," (comma chracter)

Is there anyway for me to split the phone number(s) into variable? Let say the field contain 2 phone numbers, the code will give $phone1 or $phone[1] contain phone number 1 and $phone2 or $phone[2] contain phone number 2 or even $phone3 if the field contain 3 phone numbers.

Figure it for few days but cant find a solution for this :P(

Thanks a bunch before!! :mellow:

Share this post


Link to post
Share on other sites
GEOSoft

I have a field that is a memo type, contain phone number(s).

This field can contain only 1 phone number or more than 1 phone number separated by either "/" character, newline (@CRLF) and/or "," (comma chracter)

Is there anyway for me to split the phone number(s) into variable? Let say the field contain 2 phone numbers, the code will give $phone1 or $phone[1] contain phone number 1 and $phone2 or $phone[2] contain phone number 2 or even $phone3 if the field contain 3 phone numbers.

Figure it for few days but cant find a solution for this :P(

Thanks a bunch before!! :mellow:

It can be done with a StringRegExp() but I have a couple of questions before I go there.

Are the phone numbers all in the same format?

How are the phone numbers formatted?


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
michaelslamet

Mr Nice Guy, thanks for your help :mellow:

No, they are not all in the same format.

These are possible format:

(areacode)PhoneNumber ex: (045)12344321

(areacode) PhoneNumber ex: (045)12344321

areacode-PhoneNumber ex: 0451-12344321

mobilenumber ex: 0832112121211

I think what I need to do is split them up based on their delimiters (in this case they are / or , or @CRLF)

Thanks a lot :P

It can be done with a StringRegExp() but I have a couple of questions before I go there.

Are the phone numbers all in the same format?

How are the phone numbers formatted?

Share this post


Link to post
Share on other sites
GEOSoft

$sStr = "(045)12344321" & @CRLF
$sStr &= "045-12344321, 0451-12344321,(045)12345678" & @CRLF
$sStr &= "0832112121211/(045)12344321"
$aNums = StringRegExp($sStr, "([\d\(\)-]+)(?:/|\v|,|\z)", 3);; returns a 0 Based array
If NOT @Error Then
    For $i = 0 Ubound($aNums) -1
        MsgBox(0, "Result", $aNums[$i])
    Next
EndIf

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
michaelslamet

Wow, this is a amazing litte piece of code :mellow:)

Many thanks, Mr Nice Guy, will try it shortly later in the office.

Thanks alot, again!!

$sStr = "(045)12344321" & @CRLF
$sStr &= "045-12344321, 0451-12344321,(045)12345678" & @CRLF
$sStr &= "0832112121211/(045)12344321"
$aNums = StringRegExp($sStr, "([\d\(\)-]+)(?:/|\v|,|\z)", 3);; returns a 0 Based array
If NOT @Error Then
    For $i = 0 Ubound($aNums) -1
        MsgBox(0, "Result", $aNums[$i])
    Next
EndIf

Share this post


Link to post
Share on other sites
GEOSoft

Glad to help.

String Regular Expressions are very powerfull and should be used when required but I do not advocate their abuse. That is, using them when a simple String function will do the job.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
michaelslamet

@GEOSoft: I already try the code, and it works perfectly :mellow: I modified it a little to:

"([\d\(\ )-]+)(?:/|;|\v|,|\z)"

Since I found sometime there is a ";" character as a delimiter.

Now there is another problem :party:

I thought it will easy to separate the email field by modifing the regexp you posted before, but I was so wrong :P

I have a string that can contain a email address, 2 email address(es) or even 3 email address(es)

this is the example of the string:

abc@abc.com

or

abc@abc.com / xyz@xyz.com

or

abc@abc.com / xyz@xyz.com, aaa@aaa.com

A character that separate those address(es) is either / , or ;

How the separate them into email_adress[1], email_address[2], email_address[3]? What regexp should I use?

Thanks a lot!! (again) :party:)

Best regards,

Michael

Glad to help.

String Regular Expressions are very powerfull and should be used when required but I do not advocate their abuse. That is, using them when a simple String function will do the job.

Share this post


Link to post
Share on other sites
GEOSoft

$sStr = "abc@abc.com" & @CRLF
$sStr &= "abc@abc.com / xyz@xyz.com" & @CRLF
$sStr &= "abc@abc.com / xyz@xyz.com, aaa@aaa.com"
$aEmail = StringRegExp($sStr, "\b(\S+@\S+)\b", 3)

Another way if doing this would be to replace all the separators first and then use string split

$sStr = "abc@abc.com" & @CRLF
$sStr &= "abc@abc.com / xyz@xyz.com" & @CRLF
$sStr &= "abc@abc.com / xyz@xyz.com, aaa@aaa.com"
$sRepl = StringRegExpReplace($sStr, "([/s,/;\v]+)", "\|");; Replace vertical spaces, separators and horizontal spaces on either side of them with a pipe
$sRepl = StringRegExpReplace($sRep, "\|+$", "") ;; In case there were empty lines at the end of the file
$aEmail = StringSplit($sRepl, "([/s,/;\v]+)", "\|", 2) ;; Creates a 0 based array.

EDIT: Neither of these checks for Email address validity. If you need that one, let me know. I already have it.

If you want to work with SRE's then go here.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.