FAQ  •  Register  •  Login

Iterate through characters of a string?

<<

slenkar

Posts: 282

Joined: Sun Feb 13, 2011 3:33 am

Location: Kentucky US, used to be Birmingham UK

Post Fri Jul 28, 2017 6:21 pm

Iterate through characters of a string?

How does someone get each character of a string?

(im trying to do wordwrap for a large string)

oh I got the word wrap working now:
  Code:
dim printwidth=28

Let a$="PART 1 Bruce Hall, a slightly built youth 16 years of age, fair haired and blue eyed, stood 4' 8 in shoes and despite that slight assistance still could not see over the brick wall behind which he believed stood a flying machine. At least that was what he'd overheard two delivery boys discussing outside the local butchers shop."

REM pRINT a(1 to 10)
dim stringpos as integer
stringpos=0
dim lines as integer
dim sentenceEnd as integer
while stringpos<len(a)
sentenceEnd=stringpos+printwidth

if sentenceEnd<len(a) then

FOR stringposIter=sentenceEnd TO stringpos STEP -1
if code(a(stringposIter to stringposIter))=code(" ") then

print at lines,0;a(stringpos to stringposIter)

stringpos=stringposIter
exit for
end if
next

end if

if sentenceEnd>len(a) then
print at lines,0;a(stringpos to sentenceEnd)
exit while
end if

lines=lines+1

wend

is there an escape code for carriage return or newline?
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon Jul 31, 2017 11:29 am

Re: Iterate through characters of a string?

slenkar wrote:How does someone get each character of a string?

(im trying to do wordwrap for a large string)

oh I got the word wrap working now
[...]

cool!!! 8)

Yes, for ZX Spectrum, new line is CHR$(13) (I know, It's sooo 80's :roll: )

Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO