Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse String 1

Status
Not open for further replies.

carolynh

Programmer
Feb 13, 2004
44
US
How can I parse the following string into three different fields and/or varaibles for city, state and zip: "Cleveland,Ohio 44041
 
WELL, if you know it will ALWAYS be in that format, then

assign City = entry(1,vstring,",")
State = entry(1,ENTRY(2,vstring,",")," ")
zip = entry(2,vstring," ").

Another idea is this. Get rid of the comma:
assign vString = replace(vstring,","," ").

Now the comma is gone and it's just "Cleveland Ohio 44041" and you don't have to do the funky entry stuff above.

assign City = entry(1,vstring," ")
State = entry(2,vstring," ")
Zip = entry(3,vstring," ").

And there are many other idea's too, but these should get you started. :)

Rich
 
Rich
Thank you, I could not remember what the command was (Entry)
Thanks again
Carolyn
 
Rick
Actually I had a typo, my stirng will ALWAYS be
Cleveland, OH 44041. (space between comma and state)

And when I use the code above it tells me that;
Entry 2 is out of Range and OHIO is acutally where the zip should be and state is blank. Is it because of the space before the sate?
 
Ah, true, yes, that extra space will cause a problem. Here are two other options. One would be to completely remove the comma but leave the space:

vstring = "Cleveland, OH 44041".
vstring = REPLACE(vstring,",","").

Now each piece of information is separated by a space so you can do:

assign City = entry(1,vstring," ")
State = entry(2,vstring," ")
Zip = entry(3,vstring," ").


The other would be to use the spaces for State and Zip like this:

assign City = entry(1,vstring,",")
State = entry(1,ENTRY(2,vstring," ")," ")
zip = entry(3,vstring," ").

For State I changed vstring,"," to vstring," " and for Zip I told it to use the 3rd entry, not the 2nd.

Both ways work equally well. Which one to use? Personal preference. I would validate vstring before doing the assign to make sure the data is where I expect it. If it isn't (like there isn't a space after the comma), then I would output that string to an error log along with what the error was. Hopefully there would be very few errors, I could manually fix them, and reload them.

:)

Rich

 
How can you search a text string to find a particular character; like "&
 
Depends on what you are trying to do. MATCHES will tell you if that character/string is in the string - returns true or false. INDEX will find the first occurance of that character in the string and tell you what position it is.

Say you have a string that's "Fred&Barney" and you want to find the "&".

disp vString MATCHES("*&*") will return a TRUE.

disp INDEX(vString,"&") will return 5, meaning the "&" is the 5th character in that string.

If you have more than one "&" in the file, you'll have to do some more processing. Something like this should work:

DEF VAR vString AS CHAR NO-UNDO INIT "Fred&Barney&Wilma&Betty".
DEF VAR i AS INT NO-UNDO.

DO i = 1 TO 100:
IF INDEX(vString,"&",i) EQ 0 THEN LEAVE.
DISP INDEX(vString,"&",i)
SUBSTR(vString,INDEX(vString,"&",i),30) FORMAT "x(30)"
WITH DOWN STREAM-IO.
DOWN.
i = INDEX(vString,"&",i).
END.


There are many other ways to do this too, like a do loop checking each character. Just depends on what you want to do. :)

Hope that helps!

Rich
 
Actually I want to replace it with a space. One of our Java programs is brining in text with html codes. Like AB&C Company comes in like "AB& C Company".
 
Then you should be able to use the REPLACE command for that.

vstring = "AB&C Company".
vstring = REPLACE(vstring,"&"," ").

Rich
 
Rich
can I ask you a question off this subject line?

We have 2 db's; one is for trainging and the other is the live db. I am running a progress procedure through the Windows task manager (so it is unknown to the users that it is running). My problem is that I dont know how to tell it to run for a certain db. Right now the target for my task is:
C:\dlc91ddb\bin\prowin32.exe -p run listener.p -pf L:\ts53\takestok.pf -pf L:\ts53\connect.pf -T L:\ts53\Temp -ininame "Software\Software Solutions, Inc.\TakeStock\5.3\Progress91d" -param Version=5.3

What I would like to do is have two of them; one for the training db (for testing purposes) and one for the live db.
 
Are your database connection parameters in L:\ts53\connect.pf ? If so, you could make a copy of this file (let's call it connecttest.pf), change the db params in there and set up a separate task.

If you're connecting to the database using a CONNECT statement in listener.p, then you could extend the -param parameter to something like -param Version=5.3,db=test and again set up a separate task. Of course, you'd have to tweak listener.p to parse the param but that's pretty straightforward with a bit of list processing.

HTH,

Mike
 
We have many different databases (training, test, live, long term testing) and have a .pf for each database. As Mike said, just copy your .pf to a new name, change the database connection in there and use that one for your other connection.

Rich
 
Everything seems to be working, except for my pathing. I dont think my propath is being set anywhere, so my calls are failing (ie.. run custom/xmlquery.p). How can I get my propath set???

I am using the L:\ts53\connect.pf to connect to the db:
connect.pf
# This is the database connection parameter file.
-db domdata -H ts1 -S domdb -N TCP

takestock.pf
The L:\ts53\takestock.pf contains my other params:
# This is the parameter file under Progress 9.1.
-inp 8192
-h 6
-rand 2
-yy 1940
-mmax 16000
-D 100
-k "\\ts1\L_Drive\ts53\kwforget.lst"
-stsh 5
-dictexps
-tok 1600
-s 128
-cpstream ibm850
-nb 255
-pls
 
You may want to make a copy of your .ini file, rename it, and edit the propath in there. Then just adjust your call to suit.

Also, if you're running in a Windoze environment you'll want to prefix the -ininame parameter with -basekey INI to ensure that environment info is collected from the .ini file rather than from the registry.

Mike.
 
Returning to the original question and replies: the elimination of the comma and reliance on the space alone as a delimiter is a mistake. Many city names comprise more than one word: any of these will break your scheme.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top