Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Splitting City, State, Zip into separate fields Post Reply Post New Topic
Author Message
Kvant
Newbie
Newbie
Avatar

Joined: 12 Sep 2012
Location: United States
Online Status: Offline
Posts: 1
Quote Kvant Replybullet Topic: Splitting City, State, Zip into separate fields
     Posted: 12 Sep 2012 at 6:54am
I have a database that doesn't store City, State, Zip into seperate fields.  Instead, it has a field called "City ST Zip".  I need to parse these out into seperate fields onto a report.  I searched the forum and found out how to do it with another field I have called "Name", which included both the first and last name and the parse worked great, but it doesn't work on the "City ST Zip" field.  Here's what I was using for the Name field (Thanks, DBLank!):
 
left({Command.Name},instr({Command.Name},',')-1)
 
How can I do something simliar with the City ST Zip field?  When I browse the data it looks like this:
 
City, ST 12345
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 12 Sep 2012 at 12:01pm
I would probably use instrrev...since it counts from the end of the line...so it would be easier...I think.
 
my formula would be something like:
local stringvar temp := {table.field};
shared stringvar zip;
shared stringvar state;
shared stringvar city;
local numbervar index;
 
index := instrrev(temp, " ");
zip = mid(temp, index +1);
temp := left(temp, index -1);
index := instrrev(temp, " ");
state: = mid(temp, index + 1);
city := left(temp, index - 1);
 
depending on puntuation, you might want to do a replace for the comma and or trim to remove white space.
 
basically it is looking for th first space from the end of the string, which is the zip, then it trims off from before the space. then repeats for the state, and whatever is left is the city, this way you don't have to worry about cities with 1 or more spaces in them.
HTH
 
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum