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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More fun with strings 2

Status
Not open for further replies.

Steve688

IS-IT--Management
Oct 23, 2002
34
CA
I have a field where the first name and last name are in this format:
Smith, Adam

The following code correctly breaks down the name into seperate first and last name fields in my new table, but I encounter a substr error when the process comes across data in the field that is missing the First Name.

(Smith, ) without the quotes.

Can someone please help with getting the procedure to ignore if there is no first name after the comma-space?

Code:
var
str1          string
strc, strsz   smallint
endVar

;// populates the Firstname Lastname fields of ddscumul_WMS
str1 = rempsTC."FSNANAME"
strsz = size (str1)  ;  gets the string size of FSNANAME
strc  = str1.search(",")  ;  searches the string for the first instance of the comma
strc = strc - 1
lname = str1.substr(1,strc)
ddcTC."LAST NAME" =  lname		
strc = strc + 3				
fname = str1.substr(strc,strsz)				
ddcTC."FIRST NAME" =  fname

Thanks,

Steve
 
Yeah, substring gets you in trouble when there isn't one.
I use breakapart() instead. Not always perfect, but far more reliable.


Code:
var
  arName  array[] string
  x       longint
endvar

breakapart(rempsTC."fsnaname",arName,",")
ddcTC."LAST NAME"=arName[1]
if arName.size()>1 then
  ddcTC."FIRST NAME"=ltrim(arName[2])
endif
; just in case there are more than one commas
if arName.size()>2 then
  for x from 3 to arName.size()
    ddcTC."FIRST NAME"=ddcTC."FIRST NAME"+", "+ltrim(arName[x])
  endfor
endif




Tony McGuire
"It's not about having enough time. It's about priorities.
 
A thing of beauty. Thanks once again Tony.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top