05-01-2003, 03:39 AM
05-01-2003, 03:45 AM
well, an inefficient way off the top of my head
i'm sure there's a better, faster way using sadd but if you arent whipping out hundreds of these a second it shouldnt matter.
Code:
function reverse$ (text$)
for x% = len(text$) to 1 step -1
reversed$ = reversed$ + mid$(text$, x%, 1)
next x%
reverse$ = reversed$
end function
i'm sure there's a better, faster way using sadd but if you arent whipping out hundreds of these a second it shouldnt matter.
05-01-2003, 04:21 AM
Yes, that would work, but the teacher hasn't taught about fuctions and stuff, and she will fail u for using commands she didnt teach...were at a grade 10 level (if that helps your thinking)
05-01-2003, 05:22 AM
Just take off the function lines and it'll run once with the input provided in text$
Just for fun, I have a program that writes backwards as you type
Kinda longer than the previously posted code, huh?
Just for fun, I have a program that writes backwards as you type
Code:
DEFINT A-Z
DECLARE FUNCTION dinputPRINT$ (x1, question$, acceptable$, limit, col)
CLS
allyup$ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789 ?,."
moo$ = dinputPRINT(1, "Huh?", allyup$, 50, 15)
FUNCTION dinputPRINT$ (x1, question$, acceptable$, limit, col)
yy = CSRLIN 'yy = current y position
COLOR col: LOCATE yy, x1: PRINT question$
x$ = ""
newx = LEN(question$) + x1
DO
i$ = INKEY$
SELECT CASE i$
CASE CHR$(8)
IF LEN(x$) > 0 THEN
x$ = RIGHT$(x$, LEN(x$) - 1)
'x1 = newx + 1
'reprint the question
LOCATE yy, x1: PRINT question$
'print what has been typed
LOCATE yy, x1 + newx
PRINT x$ + SPACE$(limit - LEN(x$))
END IF
CASE CHR$(13)
EXIT DO
CASE CHR$(27)
x$ = "99"
EXIT DO
CASE ELSE
IF INSTR(acceptable$, i$) > 0 THEN
IF LEN(x$) < limit THEN
x$ = i$ + x$
LOCATE yy, x1 + newx: PRINT x$
END IF
END IF
END SELECT
WAIT &H3DA, 8
LOOP
dinputPRINT$ = x$
END FUNCTION
Kinda longer than the previously posted code, huh?
05-07-2003, 12:41 PM
This is a bit shorter than the other solution...and doesn't involve a function. It does us an array, though. There are lots of ways to do this...this is just with a minute's thought.
CLS
INPUT "input string"; a$ 'a$ is string
z = LEN(a$)
DIM temp(1 TO z) AS STRING * 1
FOR x = 1 TO z
temp((z + 1) - x) = MID$(a$, x, 1) 'transfer a$ in reverse order to array temp()
NEXT x
a$ = "" 'clear a$
FOR x = 1 TO z
a$ = a$ + temp(x) 'create new string with reverse order
NEXT x
PRINT a$
CLS
INPUT "input string"; a$ 'a$ is string
z = LEN(a$)
DIM temp(1 TO z) AS STRING * 1
FOR x = 1 TO z
temp((z + 1) - x) = MID$(a$, x, 1) 'transfer a$ in reverse order to array temp()
NEXT x
a$ = "" 'clear a$
FOR x = 1 TO z
a$ = a$ + temp(x) 'create new string with reverse order
NEXT x
PRINT a$
05-07-2003, 12:59 PM
Here's another bit of code that will reverse the letters...note it uses integer division to avoid dealing with the middle byte for strings with odd numbers of bytes...
CLS
INPUT "input string"; word$
FOR x = 1 TO LEN(word$) \ 2
a$ = MID$(word$, x, 1)
b$ = MID$(word$, 1 + LEN(word$) - x, 1)
MID$(word$, x, 1) = b$
MID$(word$, 1 + LEN(word$) - x, 1) = a$
NEXT x
PRINT word$
END
CLS
INPUT "input string"; word$
FOR x = 1 TO LEN(word$) \ 2
a$ = MID$(word$, x, 1)
b$ = MID$(word$, 1 + LEN(word$) - x, 1)
MID$(word$, x, 1) = b$
MID$(word$, 1 + LEN(word$) - x, 1) = a$
NEXT x
PRINT word$
END