stripping out text...

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
TheBigDuck
Posts: 23
Joined: Tue Nov 11, 2008 5:52 pm
Contact:

stripping out text...

Post by TheBigDuck » Tue Nov 18, 2008 8:08 pm

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?

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Tue Nov 18, 2008 8:18 pm

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.
Last edited by Janschenkel on Wed Nov 19, 2008 6:34 am, edited 1 time in total.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Tue Nov 18, 2008 9:58 pm

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.

TheBigDuck
Posts: 23
Joined: Tue Nov 11, 2008 5:52 pm
Contact:

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

Post by TheBigDuck » Wed Nov 19, 2008 4:36 pm

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

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Wed Nov 19, 2008 7:46 pm

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Post Reply