×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • 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!
  • Students Click Here

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Extracting first word of no fixed length from a string

Extracting first word of no fixed length from a string

Extracting first word of no fixed length from a string

(OP)
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?

RE: Extracting first word of no fixed length from a string

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.

RE: Extracting first word of no fixed length from a string

(OP)
How can I search for the location of the first 'space' character? Is there a function for doing that?

RE: Extracting first word of no fixed length from a string

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

RE: Extracting first word of no fixed length from a string

(OP)
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?

RE: Extracting first word of no fixed length from a string

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.

RE: Extracting first word of no fixed length from a string

(OP)
Expression system. Won't work there?

RE: Extracting first word of no fixed length from a string

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

RE: Extracting first word of no fixed length from a string

(OP)
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?

RE: Extracting first word of no fixed length from a string

Quote (PrintScaffold)

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

RE: Extracting first word of no fixed length from a string

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 winky smile

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.

RE: Extracting first word of no fixed length from a string

(OP)
John!

So to access this patricular docs I need to have NX Open help option checked while installing the NX Help?

RE: Extracting first word of no fixed length from a string

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.

RE: Extracting first word of no fixed length from a string

(OP)
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?

RE: Extracting first word of no fixed length from a string

(OP)
I installed the full help, including the API section, but I didn't get any info about splitstring. What am I doing wrong?

RE: Extracting first word of no fixed length from a string

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.

RE: Extracting first word of no fixed length from a string

(OP)
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.

RE: Extracting first word of no fixed length from a string

(OP)
And also: is it possible to merge list back into string?

RE: Extracting first word of no fixed length from a string

(OP)
John,

It seems to be working, thank you.

Do you have answers for my latter questions?

RE: Extracting first word of no fixed length from a string

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.

RE: Extracting first word of no fixed length from a string

(OP)
It's ok. I have came up with a workaround: length(splitstring(<string>,"")) returns the length of the string.

RE: Extracting first word of no fixed length from a string

Actually I was thinking of something along those lines but just hadn't tried it yet. This is what I've always liked about UG/NX, it's built well enough that you can often force it to give you what you want without fear of abusing it to badly winky smile

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.

RE: Extracting first word of no fixed length from a string

Me, too!

If that east coast software I use was 3/4 as robust as UG/NX, my life would be a lot easier!

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

Ben Loosli

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

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

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


Resources