Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Extracting first word of no fixed length from a string

Status
Not open for further replies.

PrintScaffold

Mechanical
Sep 8, 2006
453
Greetings all!

I wonder if it is possible to extract a first word from a string? For example: "Steel Hardened Polished Blah Blah" would should return "String". The problem is that word can be different and it's length is not fixed. Otherwise I would use SUBSTRING function. Any ideas?
 
Replies continue below

Recommended for you

Search for the location of the first 'space' character, which will tell you how many characters that your SUBSTRING function needs to look for.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
How can I search for the location of the first 'space' character? Is there a function for doing that?
 
GRIP had a Fndstr function. What language are you writing your code in?

blank_pos = fndstr('This is a long string',1,' ')
blank_pos would be set to 5
then use
short_string = substr ('This is a long string',1,blank_pos)
short_string would be set to 'This'

may need a -1 added to the blank_pos to get the 4 charcaters (blamk_pos-1)



"Wildfires are dangerous, hard to control, and economically catastrophic."

Ben Loosli
 
I'm not using any langauge at the moment, I'm looking into the basic functionality of expressions. Is it not achievable using only Expressions?
 
Where are you doing this substring activity? In a program or in the expression system?

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Code:
Expression name    type      Formula
m1                 string    "this is a test"
m2                 list      splitstring(m1," ")
m3                 string    first(m2)

The resulting value of m3 will be: "this".

www.nxjournaling.com
 
Cowski!

Thank you very much! It works! Brilliant!

The problems is there is no documentation on splitstring function. At least I could not find it.
Also, if I need to reference second, third, etc member of list, how must I write it? Is there a documentation on this?
 
PrintScaffold said:
Also, if I need to reference second, third, etc member of list, how must I write it? Is there a documentation on this?

In the example above, m2 is a list. You can use the list function length() to find out how many items are in the list and the nth() list function to return a specific item. Check out the list functions in the expression editor as there are other functions in there as well.

www.nxjournaling.com
 
OK, to find ALL of the KF (Knowledge Fusion) routines available to you when running NX, if you have the full help files installed (this includes the optional NX Open portion), simply open a browser window and enter the following URL...

C:\Program Files\Siemens\NX 8.5\UGDOC\html_files\nx_api\en_US\graphics\fileLibrary\nx\fusion\

...if you just accepted the defaults when you installed NX using the installshield. Is you installed NX somewhere else then you'll have to edit the path above to match that location. Now when you do this you will get an explorer window with a list of .html files whose titles will be the only real hint that you'll have as to what they are used for. To see the details of a function just double-click the .html file of interest.

Anyway, good luck and have fun ;-)

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
John!

So to access this patricular docs I need to have NX Open help option checked while installing the NX Help?
 
Yes, starting with NX 8.0 we made the installation of the NX Open documentation optional so as to save space for those people who never write any custom applications. Unfortunately, the documentation covering the KF routines accessible from the Expression system are included in that portion of the NX Help files. Note that I've asked our people to at least move the KF description files (that folder of .html files I pointed you towards earlier) to the regular NX Help files so that the context sensitive help will still be available even if you never installed the NX Open docs.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
John

Thank you! No problem with that, I can isntall the missing help components.

And a stupid question: how to measure the length of the string? Is there a function responsible for this?
 
I installed the full help, including the API section, but I didn't get any info about splitstring. What am I doing wrong?
 
Did you find the 'fusion' folder I provided the path to? If so, there should be a file there by the name of 'splitstring.html'. If you open this file it should contain a full description along with several examples of how to use this KF function. Just in case you can't find it, I've attached a copy from the NX 8.5 NX Help files.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
 http://files.engineering.com/getfile.aspx?folder=0c47a4a6-d72f-4323-96d0-179c5ed0c391&file=splitstring.html
Right now I'm away from the work computer but I will check and get back to you ASAP.

One more question: how to measure the length of the string? Is there a function responsible for this?
For example: measuring 'steel' string to return number 5.
 
John,

It seems to be working, thank you.

Do you have answers for my latter questions?
 
I'm not aware of a function which returns the length of a string. Sorry.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor