Jump to content

Substitute a 'pattern' in a string


StPeter
 Share

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

Recommended Posts

Hi,

I'm looking for a solution to find a 'pattern' in a string (not a value!), and then substitute it with another value. This substitution should be done through a script.

Practically, the string looks like this:

"99999 99999

99999 99999 99999 99999

99999 99999 99999

99999 99999 99999

99999 99999 99999 99999 99999"

Each of the 9-s above represents a number from 0 to 9. Each group contains 5 numbers.

I use this string (=field) to link this table to another one.

I would now like to limit the found records in the related table, by 'voiding' those lines in the string above that contain more than 3 groups of 99999-s.

The result-string should look like this:

"99999 99999

99999 99999 99999 x 99999

99999 99999 99999

99999 99999 99999

99999 99999 99999 x 99999 99999"

(x being a normal "x" to assure a value that has no related records, without deleting the line so that i can still re-use it afterwards)

Any profis around who ran into a similar thing?

rgds,

Link to comment
Share on other sites

Each of the 9-s above represents a number from 0 to 9.

There is no pattern to find here. You should loop through the values, testing for the value's length. If it's more than 17, skip the value - otherwise include it in the result. This could be calculated using a custom function, or use a looping script to populate the result field.

Link to comment
Share on other sites

There is no pattern to find here. You should loop through the values, testing for the value's length. If it's more than 17, skip the value - otherwise include it in the result. This could be calculated using a custom function, or use a looping script to populate the result field.

Mmm, thanks Comment ... which means i need to check character for character on a 'return' to find out where the line starts and ends ... or is there an instruction that reads an entire line at the time as well?

Link to comment
Share on other sites

Use the GetValue() function, in conjunction with a incrementing counter, e.g.:

Loop

Set Variable [ $i ; $i + 1 ]

Exit Loop If [ $ i > ValueCount ( SourceField ) ]

Set Variable [ $v ; GetValue ( SourceField ; $i ) ]

If [ WordCount ( $v ) ≤ 3 ]

Set Field ( TargetField ; List ( TargetField ; $v ) ]

End If

End Loop

Commit Records []

Link to comment
Share on other sites

This topic is 4408 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
 Share

×
×
  • Create New...

Important Information

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