How to resolve the algorithm Split a character string based on change of character step by step in the FutureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Split a character string based on change of character step by step in the FutureBasic programming language
Table of Contents
Problem Statement
Split a (character) string into comma (plus a blank) delimited strings based on a change of character (left to right). Show the output here (use the 1st example below).
Blanks should be treated as any other character (except they are problematic to display clearly). The same applies to commas.
For instance, the string: should be split and show:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Split a character string based on change of character step by step in the FutureBasic programming language
Source code in the futurebasic programming language
local fn SplitString( inputStr as Str255 ) as Str255
Str255 resultStr
NSUInteger i
if len$( inputStr ) < 2 then resultStr = inputStr : exit fn
resultStr = left$( inputStr, 1 )
for i = 2 to len$( inputStr )
if mid$( inputStr, i, 1 ) <> mid$( inputStr, i - 1, 1 ) then resultStr = resultStr + ", "
resultStr = resultStr + mid$(inputStr, i, 1)
next
end fn = resultStr
window 1
print fn SplitString( "gHHH5YY++///\" )
HandleEvents
local fn SplitString( inputStr as CFStringRef ) as CFStringRef
NSUInteger i
unichar chr, lastChr = fn StringCharacterAtIndex( inputStr, 0 )
CFMutableStringRef resultStr = fn MutableStringWithCapacity(0)
for i = 0 to len( inputStr ) - 1
chr = fn StringCharacterAtIndex( inputStr, i )
if ( chr != lastChr ) then MutableStringAppendString( resultStr, @", " )
MutableStringAppendString( resultStr, mid( inputStr, i, 1 ) )
lastChr = chr
next
end fn = resultStr
window 1
print fn SplitString( @"gHHH5YY++///\\" )
HandleEvents
You may also check:How to resolve the algorithm String length step by step in the Sparkling programming language
You may also check:How to resolve the algorithm Classes step by step in the Falcon programming language
You may also check:How to resolve the algorithm Knuth's power tree step by step in the Racket programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the PL/I programming language
You may also check:How to resolve the algorithm Loops/For step by step in the Arturo programming language