Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This has been the MOST helpful forum that I have been a part of and I want to say thank you. The tips, tricks and helpful advice that you all contribute to have been lifesavers in many instances..."

Geography

Where in the world do Tek-Tips members come from?
atgrovecity (Programmer)
13 Aug 12 17:57
Hello,

I need the code to extract the first word in a string. For some records, the the generic drug name name will only have one word, sometimes more than one word. In both scenarios I need to the code to extract the first word.

Example:

OLANZAPINE
OLANZAPINE PAMOATE

The output of both records should be just OLANZAPINE

Thanks.

Joe
hilfy ( IS/IT--Management)
13 Aug 12 18:03
Try something like this:

NumberVar i;
i := InStr({myTable.MyField}), " ");
if i > 0 then substring({myTable.MyField}, 1, i - 1) else {myTable.MyField}

-Dell

DecisionFirst Technologies - Six-time SAP BusinessObjects Solution Partner of the Year
www.decisionfirst.com

CoSpringsGuy (IS/IT--Management)
13 Aug 12 19:37
or


split({myTable.MyField}," ")[1]

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

atgrovecity (Programmer)
14 Aug 12 13:40
Thanks for your help!
Joe
jcrawford08 (TechnicalUser)
15 Aug 12 16:40
CoSpringsGuy - you'll want to have a control in case there is no second word in the string, something like this:

if instr({myTable.MyField}," ")<1 then {myTable.MyField} else split({myTable.MyField}," ")[1]

-jcrawford-

Not in word only, but in deed also... 1Jn3:18

CoSpringsGuy (IS/IT--Management)
15 Aug 12 16:49
jcrawford08 - Why do you need control? My solution works with one word or a thousand words .. try it

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

CoSpringsGuy (IS/IT--Management)
15 Aug 12 16:55
What you have been thinking was if the field is empty in which case

if len({@text1}) > 0 then split({@text1}," ")[1]

will work....

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

jcrawford08 (TechnicalUser)
15 Aug 12 16:55
My apologies, I guess that's a habit I've gotten in. I seemed to recall coming into some issues previously where without a control the split formula would error out, but the specifics must have been different than they are in this situation.

-jcrawford-

Not in word only, but in deed also... 1Jn3:18

jcrawford08 (TechnicalUser)
15 Aug 12 16:57
Thank you for vindicating that I have not lost my mind completely :)

-jcrawford-

Not in word only, but in deed also... 1Jn3:18

CoSpringsGuy (IS/IT--Management)
15 Aug 12 16:59
No probs! I have learned A LOT through this forum and mainly through discussions like this one...

_____________________________________
Crystal Reports 2008 and XI
Intersystems Cache 2012 ODBC connection

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close