Hi Slenkar!
slenkar писал(а):
how does someone go through each character of a string?
Actually if a string is array of characters, so:
Код: "OBERON"
VAR str: ARRAY 256 OF CHAR; i: INTEGER;
BEGIN
FOR i := 0 TO 255 DO C.WriteCh( str[i] ) END;
But if a string is just literal, no way to do it.
slenkar писал(а):
and split strings into smaller strings.
For this, you can use your own procedure, like
this (see Extract). Also there are Delete, Insert, Replace, Append, Concat, etc.
slenkar писал(а):
Also how do you turn a number into a string.
Код: "OBERON"
PROCEDURE IntToString* (x: LONGINT; VAR s: ARRAY OF CHAR);
VAR j, k: INTEGER; ch: CHAR; a: ARRAY 32 OF CHAR;
CONST
minLongIntRev = "8085774586302733229"; (* reversed string of -MIN(LONGINT) *)
BEGIN
IF x # MIN(LONGINT) THEN
IF x < 0 THEN s[0] := "-"; k := 1; x := -x ELSE k := 0 END;
j := 0; REPEAT a[j] := CHR(x MOD 10 + ORD("0")); x := x DIV 10; INC(j) UNTIL x = 0
ELSE
a := minLongIntRev; s[0] := "-"; k := 1;
j := 0; WHILE a[j] # 0X DO INC(j) END
END;
ASSERT(k + j < LEN(s), 23);
REPEAT DEC(j); ch := a[j]; s[k] := ch; INC(k) UNTIL j = 0;
s[k] := 0X
END IntToString;
(taken from BlackBox Component Builder)
slenkar писал(а):
This doesnt work
Str="hi this is a string";
Do you mean CONST Str="hi this is a string" here?
slenkar писал(а):
C.WriteStr(LEN(Str));
As I know, LEN doesn't work for string literals.
You can't have direct access to a string literal. Use COPY or := to initial an array, like:
Код: "OBERON"
VAR str: ARRAY 256 OF CHAR;
BEGIN
str := "This is my string literal";
COPY("This is my string literal", str);
You can also use non-standard extension of XDev - constant arrays:
Код: "OBERON"
TYPE
MsgStr = ARRAY 3, 7 OF CHAR;
CONST
Way = MsgStr("Hello","Error","Try");
TYPE
Labirint = ARRAY 3, 16 OF CHAR;
CONST
Map = Labirint(
"...o..##...oo12",
"...o..##...oo35",
"...o..##...oo78"
);
I hope I understood your questions correctly.
P.S. Do you write a game for ZX Dev Conversions party?
I know that you can't announce. Well, you at least hint.