Strip whitespace from a string/Top and tail: Difference between revisions

no edit summary
m (→‎{{header|Phix}}: removed tab nonsense)
No edit summary
Line 946:
Right trimmed => Length = 15
Fully trimmed => Length = 12
</pre>
 
=={{header|FutureBasic}}==
<lang futurebasic>window 1
 
CFCharacterSetRef set, invSet
CFStringRef s, s1, s2, s3
NSUInteger index
CFRange range
 
set = fn CharacterSetWhitespaceAndNewlineSet
invSet = fn CharacterSetInvertedSet( set )
 
text ,,,,, 200
 
s = @" a string "// 5 leading spaces, 8 trailing spaces
print s, len(s)@" chars"
 
// left trim
index = 0
range = fn StringRangeOfCharacterFromSet( s, invSet )
if ( range.location != NSNotFound ) then index = range.location
s1 = fn StringSubstringFromIndex( s, index )
print s1, len(s1)@" chars"
 
// right trim
index = len(s)
range = fn StringRangeOfCharacterFromSetWithOptions( s, invSet, NSBackwardsSearch )
if ( range.location != NSNotFound ) then index = range.location + 1
s2 = fn StringSubstringToIndex( s, index )
print s2, len(s2)@" chars"
 
// trim
s3 = fn StringByTrimmingCharactersInSet( s, set )
print s3, len(s3)@" chars"
 
HandleEvents</lang
{{out}}
<pre>
a string 21 chars
a string 16 chars
a string 13 chars
a string 8 chars
</pre>
 
408

edits