Jump to content

Set variable to content of a field from a string in that field, to the end of the field.


This topic is 730 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

I'm trying to figure out a good and semi-repurposeable way to do the following.

Set a variable to the contents of a field, starting with (and including) an identified string (in this case, the string is unique to the field, but to make the script more general, it can be the first occurrence of the string), to the end of the field.

I then want to set the field to that the value of the variable. I probably don't even need a variable, but I have been trying to use one during testing.  Set Field seems to be the best function to start with.

To clarify:

Field initial state:

<beginningTextToEliminate>

uniquestring

<endingTextToKeep>

 

Field ending state:

uniquestring

<endingTextToKeep>

--

I started out using Set Selection, and *am* able to select the text I want the field to be set to, but with no way to set the field to that selection (I don't think I can set a variable to text selected by Set Selection):

Set Selection

Start Position: Position ( notes::entry ; "uniqueString" ; 1 ; 1  )

End Position: Length ( notes::entry )

--

I am able to find the Position of the start of the string:

Position ( notes::entry ; "uniqueString" ; 1 ; 1 ) 

… but then what?

Then I tried working with RightWords:

I was able to manually get the content I want the field to be set to by manually entering the number of words:

RightWords ( notes::entry ; 15 )

… which works, but I want to be able to write a calc that determines what those (15, or whatever) number of words are.

thanks

Edited by Bob47
Link to comment
Share on other sites

Here is one way:

Right ( YourField ; Length ( YourField ) - Position ( YourField ; "uniquestring" ; 1 ; 1 ) + 1 )

Here's another:

Replace ( YourField ; 1 ; Position ( YourField ; "uniquestring" ; 1 ; 1 ) - 1 ; "" )

The first one extracts the "tail" of the text, while the latter removes the leading part.

 

You could also do:

Middle ( YourField ; Position ( YourField ; "uniquestring" ; 1 ; 1 )  ; Length ( YourField ) )

but that's kind of clunky.

 

Edited by comment
  • Like 1
Link to comment
Share on other sites

  • Newbies

I tried all three methods, and all work perfectly. I appreciate your help, and a bonus for providing multiple options. Thanks!

Edited by Bob47
Link to comment
Share on other sites

This topic is 730 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.