Posted: 1st Jan 2003 23:34
Here is the first version of my wordwrap. If the string is too long then it makes it into 2 shorter strings

+ Code Snippet
test$="THIS IS A TEST STRING- I AM MAKING IT WAY TOO LONG FOR A REASON"
stringlength#=len(test$)
halfway#=len(test$)/2
if len(test$)>20
cls
print left$(test$,halfway#)
print right$(test$,halfway#+1)
else 
print test$
endif


Remember this is a very, very first version of it. When I finish it will be better

For those of you who cant use code windows, heres the code out of it

test$="THIS IS A TEST STRING- I AM MAKING IT WAY TOO LONG FOR A REASON"
stringlength#=len(test$)
halfway#=len(test$)/2
if len(test$)>20
cls
print left$(test$,halfway#)
print right$(test$,halfway#+1)
else
print test$
endif

RPGamer
Posted: 2nd Jan 2003 0:26
Perhaps I can help.

+ Code Snippet
sync on : sync rate 60

s$="Mary had a little lamb, it's fleece was white as snow, and every where that Mary went, "
s$ = s$ + "she made sure she had a bottle of mint sauce, a bag of potatoes and some vegetables!"

WordWrap(s$)

sync
wait key
end


function WordWrap(s$)
  repeat
    pos = 0

    rem --- read line from string
    repeat
      pos = pos + 1
    until (text width(left$(s$,pos)) >= bitmap width()) or (pos = len(s$))

    rem --- if word has wrapped then reduce line to last space
    if pos < len(s$)
      while mid$(s$,pos) <> " "
        pos = pos - 1
      endwhile
    endif

    rem --- display line and remove it from string
    print left$(s$,pos)
    s$ = right$(s$,len(s$) - pos)

  until s$ = ""
endfunction


(sheds a tear for the lamb)...sniff
Posted: 2nd Jan 2003 18:28
Heheehhe I was just going to go about coding that too Good thing my code from my head was simliar too that Great minds think alike

RPGamer
Posted: 2nd Jan 2003 20:08
Thanks EC, I've used a version of that for my purposes (It was faster than my attempt at the same sort of thing)

Any way of speeding it up I wonder. String Manipulation seems pretty slow in DBPro.

Jas
Posted: 2nd Jan 2003 22:53
I always suggest making things yourself I really posted this for learning purposes- and if someone wanted to do things the quick way then they can use it. Then EC came along and stole my post....... JK man nice code Well, I guess there is really no point in changing mine now!

RPGamer
Posted: 2nd Jan 2003 23:37
D'oh! (slaps forhead), Sorry, I had not considered that

I will now write out 1000 times: "I will not interfere with other peoples posts!"
Posted: 3rd Jan 2003 0:29
..hmmm, I think:

until (text width(left$(s$,pos)) >= bitmap width()) or (pos = len(s$))

should idealy be:

until (text width(left$(s$,pos)) > bitmap width()) or (pos = len(s$))
Posted: 3rd Jan 2003 4:52
Yep- good plan
Posted: 3rd Jan 2003 15:54
ahhhh... but if you have a word that is longer than a line then it gets stuck in a loop. Just something else for u to do.
Posted: 3rd Jan 2003 18:52
Well....I don't think anyone is going to have any words like "Antidisestablishmentarianism" in their program, heh.
Posted: 9th Jan 2003 4:07
Ya but you could have a character be like surprised and say like ad;flafdafdj Lol..... maybe
Posted: 6th Feb 2003 2:00
EC, how do you get your program to recognize the words in the string? I'm trying to make a sentence recognition program and need to be able to read individual words.
Posted: 6th Feb 2003 3:26
If you're using DBPro, you may wish to try this:

+ Code Snippet
dim wordlist$(0)

lastword = ReadWords("Take all but leave the key and then go west","",1)

for i = 0 to lastword
  print wordlist$(i)
next i

sync
wait key
end


function ReadWords(s$, filter$,changecase as byte)
  rem --- s$ = string to be processed
  rem --- filter$ = characters to be removed
  rem --- changecase = change case (1 = lower, 2 = upper, else no change)

  empty array wordlist$()

  ln = len(s$) : if ln = 0 then exitfunction 0
  lf = len(filter$)
  wrd$ = "" : pos = 0

  rem --- change case if requested
  if changecase = 1 then s$ = lower$(s$)
  if changecase = 2 then s$ = upper$(s$)

  repeat
    inc pos,1
    lett$ = mid$(s$,pos)

    if lett$ = " " or pos > ln
      if wrd$<>""
        array insert at bottom wordlist$()
        wordlist$(array count(wordlist$())) = wrd$
        wrd$=""
      endif
    else
      filt = 0
      for f = 1 to lf
        if mid$(filter$,f) = lett$ then filt = 1
      next f
      if filt = 0 then wrd$ = wrd$ + lett$
    endif

  until pos > ln

endfunction array count(wordlist$())
Posted: 6th Feb 2003 3:28
...I hope this is what you need
Posted: 6th Feb 2003 3:51
Umm, is there any way I could use that on DBC w/dark matter?
Posted: 6th Feb 2003 4:12
Try this:

+ Code Snippet
wordmax = 200
dim wordlist$(wordmax)

lastword = ReadWords("Take all but leave the key and then go west","")

for i = 0 to lastword
  print wordlist$(i)
next i

sync
wait key
end


function ReadWords(s$, filter$)
  rem --- s$ = string to be processed
  rem --- filter$ = characters to be removed

  for i = 0 to wordmax : wordlist$(i)="" : next i

  ln = len(s$) : if ln = 0 then exitfunction 0
  lf = len(filter$)
  wrd$ = "" : pos = 0

  index = -1
  repeat
    inc pos,1
    lett$ = mid$(s$,pos)

    if lett$ = " " or pos > ln
      if wrd$<>""
        index = index + 1
        wordlist$(index) = wrd$
        wrd$=""
      endif
    else
      filt = 0
      for f = 1 to lf
        if mid$(filter$,f) = lett$ then filt = 1
      next f
      if filt = 0 then wrd$ = wrd$ + lett$
    endif

  until pos > ln

endfunction index
Posted: 6th Feb 2003 15:07
Is there a way you could store the words in an array?
Posted: 6th Feb 2003 22:34
The words are stored in the wordlist$() array in the new example.

...unless you're having trouble getting the example to work?
Posted: 6th Feb 2003 23:27
I was already doing this but thanx 4 confirming I was doing it properly

A sensible time when a single word might be long than one line is a weblink, Eg

http://www.unnecessarily-long-hosting-provider.org.uk/free-space-user/mypage.html

OR even more pheasably:
http://www.google.com/search?q=kangaroo2+darkbasicpro+bounce&btnG=Google+Search&hl=en&lr=&ie=UTF-8&oe=UTF-8

HEY I'm number 1 on Google! lol

Admittedly there are ways round that, but just tht I'd point out its not as unncommon as you might think.
Posted: 8th Feb 2003 1:20
This is the first version of the learning program. the only problem is that it won't write to a file if it already exists!! can u help me with this?