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

returning the 2nd word in a string 1

Status
Not open for further replies.

mdtimo

Programmer
Oct 18, 2001
38
US
I have a string that always starts with a name. It would be something like this:

Jim Green labor certification.

I want to pull out Green.

I only want to display "Green".
 
if you have CR8.x you can do this:

StringVar array strA;
strA := split({YourString}, " ");
strA(1)

if you have an earlier version without the Split function:

StringVar s := Mid(Trim({YourString}),Instr(Trim({YourString})," "));
Mid(s, Instr(s," ")
 
if you have CR8.x you can do this:

StringVar array strA;
strA := split({YourString}, " ");
strA(1)

if you have an earlier version without the Split function:

StringVar s := Left(Trim({YourString}),Instr(Trim({YourString})," "));
Left(s, Instr(s," ")
 
Rogar...I don't think your second formula quite works.

StringVar s := Left(Trim({YourString}),Instr(Trim({YourString})," "));
Left(s, Instr(s," ")


You are grabbing only the first word for s...not the second one

I might try this

WhilePrintingRecords;
numbervar pos1 := 0;
numbervar pos2 := length(trim({Table.YourString})) + 1;

pos1 := Instr(trim({Table.YourString})," ");
//there is no garuantee that there is a third word
//though from the example given that doesn't seem to be a
//problem and the "IF" test can be removed
if Instr(trim({Table.YourString}),pos1,&quot; &quot;) <> 0 then
pos2 := Instr(trim({Table.YourString}),pos1,&quot; &quot;);

mid(trim({Table.YourString}),pos1 + 1,pos2 - 1);

Jim Broadbent
 
Jim -
You are right. I didn't think this through before posting. What I had in mind was to clip off the first word with
StringVar s := Mid(Trim({YourString}),Instr(Trim({YourString}),&quot; &quot;));
and then to return the second word with
Left(s,Instr(s, &quot; &quot;))


 
Another way this can be achieved is by downloading the UFL from the Crystal decision website called UFLTECH1.EXE. Once this is installed you will have a function called 'GetWord' and its syntax is -
GetWord ({Table.Field}, 2)
Where the 2 signifies the word count.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top