stripping out text...
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 23
- Joined: Tue Nov 11, 2008 5:52 pm
- Contact:
stripping out text...
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?
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?
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
I'll give it a shot - assuming the data is in the variable 'tText':
HTH,
Jan Schenkel.
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
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
www.quartam.com
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 toThat would rely on having no inconsistencies with underscore characters in the data lines.
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
-
- Posts: 23
- Joined: Tue Nov 11, 2008 5:52 pm
- Contact:
Thanks for the pointer, but I think this might more elegant.
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
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
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.
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
www.quartam.com