AnsweredAssumed Answered

How to select a string in a text field and change its format

Question asked by wladdy on Apr 10, 2011
Latest reply on Apr 12, 2011 by rjlevesque

Title

How to select a string in a text field and change its format

Post

I have a text field in which all the records have the following format:

"[string1]
Key expression: [string2]
[string 3]"

80% of the time [string 2] will be a direct extraction from [string1]. For instance, a record could be :

"Now is the winter of our discontent
made glorious summer by this sun of York
Key expression: winter of our discontent
This is the opening line from Richard III".

My goal is to write a script that will automatically change the format of [string2] within [string1], say by underlining. In my example, the desired output would be:

"Now is the winter of our discontent
made glorious summer by this sun of York
Key expression: winter of our discontent
This is the opening line from Richard III".

I figured out that I could select [string2] by using Step Selection with the following parameters:

Start Position = Position ( Table::Field ; "Key expression:" ; 1 ; 1 ) + 16
End Position = Position ( Table::Field ; Char (13)  ; Position ( Table::Field; "(A)" ; 1 ; 1 ) ; 1 ) – 1

I do not know where to get from here. My intuition is to do the following:

1) save the selection (that is [string2]) inside a local variable called $KeyExpression
2) run Step Selection again using $KeyExpression in the parameters to select the first occurrence of [String2] in Table::Field
3) somehow use the function 'TextStyleAdd' to underline the new selection

Unfortunately, I cannot figure out how to

1) save a text selection inside a variable (PhilModJunk wrote in a threat to avoid using the clipboard so I want to follow that recommendation)
2) change the formatting of a text selection inside a field

Alternatively, maybe my entire approach is flawed. In any case, suggestions to put me on the right path would be greatly appreciated. W.

Outcomes