Jump to content
Macro Express Forums

Breaking Up A String: Help!


konstantin

Recommended Posts

Try something like this:

// Input string is in T1
//  
// Copy string to T4
Variable Modify String: Copy %T1% to %T4%
//  
// Put the position of the first space in T4 into N1
Variable Set Integer %N1% from Position of Text in Variable %T4%
// Decrement to skip the space
Variable Modify Integer: Dec (%N1%)
// Copy everything to T2
Variable Modify String: Copy Part of %T4% to %T2%

// Increment to include the space
Variable Modify Integer: Inc (%N1%)
// Delete the first word, including the space
Variable Modify String: Delete Part of %T4%

// REPEAT to get the second word, except place result into T3

// Put the position of the first space in T4 into N1
Variable Set Integer %N1% from Position of Text in Variable %T4%
// Decrement to skip the space
Variable Modify Integer: Dec (%N1%)
// Copy everything to T3
Variable Modify String: Copy Part of %T4% to %T3%

// Increment to include the space
Variable Modify Integer: Inc (%N1%)
// Delete the first word, including the space
Variable Modify String: Delete Part of %T4%


// Here:
//     T1 contains the original string
//     T3 contains the first word
//     T4 contains the second word
//     T2 contains the third word

Make sure that you put a space in the Search Text field inside the Variable Set Integer %N1% from Position of Text in Variable %T4% commands.

Link to comment
Share on other sites

  • 4 months later...
Try something like this:

CODE 

// Input string is in T1

// 

// Copy string to T4

Variable Modify String: Copy %T1% to %T4%

// 

// Put the position of the first space in T4 into N1

Variable Set Integer %N1% from Position of Text in Variable %T4%

// Decrement to skip the space

Variable Modify Integer: Dec (%N1%)

// Copy everything to T2

Variable Modify String: Copy Part of %T4% to %T2%

 

// Increment to include the space

Variable Modify Integer: Inc (%N1%)

// Delete the first word, including the space

Variable Modify String: Delete Part of %T4%

 

// REPEAT to get the second word, except place result into T3

 

// Put the position of the first space in T4 into N1

Variable Set Integer %N1% from Position of Text in Variable %T4%

// Decrement to skip the space

Variable Modify Integer: Dec (%N1%)

// Copy everything to T3

Variable Modify String: Copy Part of %T4% to %T3%

 

// Increment to include the space

Variable Modify Integer: Inc (%N1%)

// Delete the first word, including the space

Variable Modify String: Delete Part of %T4%

 

 

// Here:

//    T1 contains the original string

//    T3 contains the first word

//    T4 contains the second word

//    T2 contains the third word

 

 

Make sure that you put a space in the Search Text field inside the Variable Set Integer %N1% from Position of Text in Variable %T4% commands.

 

 

--------------------

 

Kevin Heaton

Insight Software Solutions, Inc.

 

I've tried this and i can get it to work with the "John Adams Micheals" example, but what if i have a list of different names with different length. As i understand you have to define stating position and characters to delete in for instance

Variable Modify String: Delete Part of %T4%
and thats the trouble when it varys.

 

Is there something that i've missed?

It could be very useful if this would work regardless of the length of the names.

Thanx in advance.

Link to comment
Share on other sites

It could be very useful if this would work regardless of the length of the names.
The example works with names of 1, 2 and 3 words. Each word, separated by a space, can be any length. If you need to parse names with 4 or more words then you can use the example as a pattern and extend it.

 

Use the Variable Set Integer %N1% from Position of Text in Variable %T4% command to find where the space is in the string (the position is in N1). Then use that value (N1) in the Variable Modify String: Copy Part of %T4% to %T2% command.

Link to comment
Share on other sites

Thanks for you're quick answer Kevin.

I'm sorry to say that we still don't understand how it works.

We're getting the bit were you define %N1% to space then we're lost at the bit were you define the number of character to copy and delete becuse the length of the names are different every time. We're stuck on this and we would really get this to work since it would be very useful in handling information from another prog. that we use.

 

Perhaps you could make the script and post it as a Direct Editor script. We then could implement this in the macro to better understand how it work.

 

Thanks in advance.

Link to comment
Share on other sites

  • 2 years later...

I am trying to do this but am having some difficulty with one part of the code.

First when you say "Variable modify string copy part of %T4% to %T2%"

 

Well the box says start position: and Character to Copy.

 

I am guessing that this would be Variable T4 but you cant do this.

It would not be Variable N1 because this was set to get rid of a space position after the first name. I am using Kelly Alexander for mine for instance. If I can get it to output the first name I am sure I can copy the 2nd name with no problem.

 

What I am hoeing is if I can get macro express to notes the first space in the names string then copy all the info in from there to the start of the string aka "Kelly" then look for the end of the text and colly to the next closes space aka "Alexander" The reason I am going this cout is because some people tickets are put in with a first middle last name and others are only first and last name. All I want is there first name and there last name thought to move to the next part of the ticket system so I need to find a way to copy there WHOLE name then pars out there first and last names then save those as separate interagers to use later on.

 

Love any help ppl can provide. I tried take the mxl file on this but that is just a executing of a macro but dose not let me look at the source code.

Link to comment
Share on other sites

If you download the actual macro file, you'll be able to open that command and see where the start position actually is (could be a comma, a space, or a specific series of characters).

 

I downloaded the macro in this but it simply executes instead of allowing me to see the code that's available. I guess I can see how you would tell it to start but the question is how do you get it to start at the beging of the name. I would guess the 2nd box you put the variable %N1% sense you all ready set this as the first space in the name.

Link to comment
Share on other sites

I downloaded the macro in this but it simply executes instead of allowing me to see the code that's available.

If you click on the downloaded file then it will execute. Instead, from within the Macro Express Editor, click File, Import, Import Macros, Import a Playable Macro. This will import the macro into your existing macro file so you can view it.

Link to comment
Share on other sites

If you click on the downloaded file then it will execute. Instead, from within the Macro Express Editor, click File, Import, Import Macros, Import a Playable Macro. This will import the macro into your existing macro file so you can view it.

 

Thank you for this! I was able to import the code and am now re processing it down this is perfect ^.^

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...