February 25, 2021, 02:23:00 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bmx] Word Wrap - Version #1 by Shortwind [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bmx] Word Wrap - Version #1 by Shortwind [ 1+ years ago ] (Read 960 times)
BlitzBot
Jr. Member
Posts: 1
[bmx] Word Wrap - Version #1 by Shortwind [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:43 AM »
Title :
Word Wrap - Version #1
Author :
Shortwind
Posted :
1+ years ago
Description :
Usefull word wrap routine for restricting printing of strings to a specific width. It correctly handles 99% of all these situations, including correct printing when a section of text with out spaces is longer than the specified width. This routine can easily be adapted to other situations.
Code :
Code: BlitzMax
SuperStrict
Local
a:
String
=
"This string is very long and we (x+y=34*sqr(z)/cos(r)*pi+(x*y)/87) will test various length texts."
+..
" To test these functions for proper goodness is the stuff of dreams. And "
+..
"the dreams are (x+y=34*sqr(z)/cos(r)*pi+(x*y)/87) here and not there. But what if the dreams and here"
+..
" and not there? Well, if the first and second part are not in the third part then the third part is "
+..
"not the circle of the square. But sometimes things are not as they seem. Even though the seem is there,"
+..
"it may not be there when we look into the seemingly endlessness of space and time... Oh, but there is"
+..
"no time like the present even though there is no present in the time of the timeness that is time."
Local
boxwidth:
Int
=
20
DoMyWrap
(
a, boxwidth
)
End
'------------------Start of Function ----------------------------
Function
DoMyWrap
(
a:
String
, width:
Int
)
Local
s:
Int
, e:
Int
s=
1
e=width
While
s<
Len
(
a
)
If
Len
(
a
)
<e
Then
Print a
Exit
ElseIf
s+e>=
Len
(
a
)
Then
Print
Mid
(
a,s
)
Exit
End
If
While
Mid
(
a,s+e,
1
)
<>
" "
And
e>
0
e=e-
1
Wend
If
e=
0
Then
Print
Mid
(
a,s,width
)
s=s+width
e=width
Else
Print
Mid
(
a,s,e
)
s=s+e+
1
e=width
End
If
Wend
End
Function
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bmx] Word Wrap - Version #1 by Shortwind [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal