Page 1 of 1

stripping out text...

Posted: Tue Nov 18, 2008 8:08 pm
by TheBigDuck
I have lines of text that look like this...

blahblahblah_T_alltheimportantstuff
blah_T_othertheimportantstuff

I want to strip out EVERYTHING prior to the T so it looks like this...

T_alltheimportantstuff
T_othertheimportantstuff

any suggestions?

Posted: Tue Nov 18, 2008 8:18 pm
by Janschenkel
I'll give it a shot - assuming the data is in the variable 'tText':

Code: Select all

repeat for each line tLine in tText
  put offset("_T_", tLine) into tOffset
  if tOffset = 0 then
    put tLine after tNewText
  else
    put char tOffset + 1 to -1 of tLine after tNewText
  end if
  put return after tNewText
end repeat
delete char -1 of tNewText  -- strip the trailing return
HTH,

Jan Schenkel.

Posted: Tue Nov 18, 2008 9:58 pm
by SparkOut
How regular are the lines of text, and the consistency of the delimiter?
If it's always of the format blahblah_T_keepme then you might be able to

Code: Select all

set the itemDelimiter to "_"
repeat for each line tLine in tText
  put item 2 to -1 of tLine & cr after tNewText
end repeat
delete char -1 of tNewText
That would rely on having no inconsistencies with underscore characters in the data lines.

Thanks for the pointer, but I think this might more elegant.

Posted: Wed Nov 19, 2008 4:36 pm
by TheBigDuck

Code: Select all

repeat for each line text_line in variableContainer

      put offset ("_T_", text_line) into off_set // find where the _T_ occurs
      delete char 1 to off_set of template_line  // blast everything from ONE to the offset
     
end repeat
I think this is a bit simpler

Posted: Wed Nov 19, 2008 7:46 pm
by Janschenkel
The reason why I went the roundabout way of building up a new text variable, is that you shouldn't attempt to modify either the 'singe line' or 'entire text' variables while you're in a 'repeat for each' loop.
Also, the original poster wanted the underscore before the 'T_' to be removed as well, so you have to use the offset + 1.

Jan Schenkel.