Jump to content

Truncate large string


homemade
 Share

Recommended Posts

This is the large string that I want to truncate

Residential Status: Active LP: $3,495,000 Sales MLS #: 000000 Orig.Price: $3,695,000 Price: MT: 273 APN: 000-00 List Date: 02/11/2009 AMT: 269 Listing Type: Exclusive Agency (A) Court/Lndr Apprvl Needed: N Address: 16595 La Gracia Unit#/Space#: City: Rancho Santa Fe, CA Zip: 92067 MapCode: 1164D4 Bedrooms: 5 Year Built: 1990 Zoning: RR1 Units In Complex: Media: 12 - VT: http://www.previewfirst.com/ REMARKS AND SHOWING INFO Confidential Remarks: Showing Instructions: CLOFATS LISTING AGENT AND OFFICE INFORMATION Listing Agent: This Person (00000) Agent Phone: (000) 000-4024 Add'l Phone: (000) 000-4024 2nd Agent: Jason A. (000) 2nd Agt Phone: (000) 000-4024 2nd Add'l Phone: (000) 000-4024 Listing Office: Estates, Inc. Office Phone: (000) 000-4024 Broker Office ID: 000 Email: thisemail@aol.com Fax: (000) 000-9553 Pager: SOLD INFORMATION Off Market Date: Close of Escrow: Expiration Date: Sale Price: Selling Agent

I want to have 2 variables. One storing the listing agent data and the other for the email.

For the agent name, his license number is usually included so if possible I'd like to not include that.

The length of this large string is never constant due to all the other data involved.

Any help is appreciated, thank you.

Link to comment
Share on other sites

This may give you a few ideas.

local $sStr = "Residential Status: Active LP: $3,495,000 Sales MLS #: 000000 Orig.Price:" & _
        "$3,695,000 Price: MT: 273 APN: 000-00 List Date: 02/11/2009 AMT: 269 Listing Type: " & _
        "Exclusive Agency (A) Court/Lndr Apprvl Needed: N Address: 16595 La Gracia Unit#/Space#: " & _
        "City: Rancho Santa Fe, CA Zip: 92067 MapCode: 1164D4 Bedrooms: 5 Year Built: 1990 Zoning: " & _
        "RR1 Units In Complex: Media: 12 - VT: http://www.previewfirst.com/ REMARKS AND SHOWING INFO " & _
        "Confidential Remarks: Showing Instructions: CLOFATS LISTING AGENT AND OFFICE INFORMATION Listing Agent: " & _
        "This Person (00000) Agent Phone: (000) 000-4024 Add'l Phone: (000) 000-4024 2nd Agent: " & _
        "Jason A. (000) 2nd Agt Phone: (000) 000-4024 2nd Add'l Phone: (000) 000-4024 Listing Office: " & _
        "Estates, Inc. Office Phone: (000) 000-4024 Broker Office ID: 000 Email: thisemail@aol.com Fax: " & _
        "(000) 000-9553 Pager: SOLD INFORMATION Off Market Date: Close of Escrow: " & _
        "Expiration Date: Sale Price: Selling Agent "

local $sListing = StringRegExpReplace($sStr,"(.*)Listing Agent:.*(Listing Office:.*)Email: .*","\1 \2")
MsgBox(0,"Listing",$sListing)

local $sEmail = StringRegExpReplace($sStr,".*(Email: .*)","\1")
MsgBox(0,"Email",$sEmail)
Link to comment
Share on other sites

I tweaked your code to this

$sListing = StringRegExpReplace($sHTML,".*(Listing Agent:.*)Agent Phone: .*","\1 \2")

and I also added

$sShort = StringReplace($sListing, "Listing Agent: ", "")

I have the name now but it has the license number attached. For example. Betty Crocker (123456). Is there any way to get rid of the #s?

Link to comment
Share on other sites

No problem. Just now I played around with some back-referencing(inspired by Malkey's post) and this is what I've got so far:

#include <Array.au3>

$string = "Residential Status: Active LP: $3,495,000 Sales MLS #: 000000 Orig.Price: $3,695,000 Price: MT: 273 APN: 000-00 List Date: 02/11/2009 AMT: 269 Listing Type: Exclusive Agency (A) Court/Lndr Apprvl Needed: N Address: 16595 La Gracia Unit#/Space#: City: Rancho Santa Fe, CA Zip: 92067 MapCode: 1164D4 Bedrooms: 5 Year Built: 1990 Zoning: RR1 Units In Complex: Media: 12 - VT: http://www.previewfirst.com/ REMARKS AND SHOWING INFO Confidential Remarks: Showing Instructions: CLOFATS LISTING AGENT AND OFFICE INFORMATION Listing Agent: This Person (00000) Agent Phone: (000) 000-4024 Add'l Phone: (000) 000-4024 2nd Agent: Jason A. (000) 2nd Agt Phone: (000) 000-4024 2nd Add'l Phone: (000) 000-4024 Listing Office: Estates, Inc. Office Phone: (000) 000-4024 Broker Office ID: 000 Email: thisemail@aol.com Fax: (000) 000-9553 Pager: SOLD INFORMATION Off Market Date: Close of Escrow: Expiration Date: Sale Price: Selling Agent"

; array style
$array = StringRegExp($string,"[\w][\w\s]+(?=\(\d{5}\))|[\w._-]+@[\w._-]+",3)
_ArrayDisplay($array)

; plain text
$text = StringRegExpReplace($string,".*((?<=:\s)[\w\s]+(?=\s\(\d{5}\))).*((?<=\s)[\w._-]+@[\w._-]+).*","Name: \1, Email: \2")
MsgBox(0,"",$text)

Wow, regular expressions are extremely powerful... :)

Hi ;)

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...