LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Strings being Arrays

Root / Programming Questions / [.]

MariominerCreated:
So I've heard that Strings are basically just arrays referencing ASCII values of characters. I tested this, as I remembered it from C, and it did indeed return "H" when saying PRINT "HELLO WORLD"[0]. But is there anything that you can do with this knowledge, like setting maybe arrays to strings like DIM HI$[5]:HI$="HELLO" or something? Or do you have to do it bit per bit like
DIM HELLO$[0]
HI$="HELLO"
FOR I=O TO LEN(HI)-1
HELLO$[I]=HI$[I]
NEXT
Or would that not even work? I'd just want a base to work off of.

A string is an array of characters, where's your HELLO$ is an array of strings. Since SmileBASIC doesn't give us access to a char variable type, my guess is that this isn't gonna work. But the only way to know for sure is to test it for real!

I wonder if there is a way to have the array be of characters. I wish that we could access all of the types, like Null (None, or whatever you want to call it), unless there is a constant that already is that to use... It wouldn't be too much better, but not too much can be a heck of a lot in a creative mind.

I wonder if there is a way to have the array be of characters. I wish that we could access all of the types, like Null (None, or whatever you want to call it), unless there is a constant that already is that to use... It wouldn't be too much better, but not too much can be a heck of a lot in a creative mind.
AFAIK, Null doesn't have any meaning without object-oriented programming. Or rather, Null can't exist outside of OOP. Since BASIC (and smileBASIC) aren't object-oriented languages, there can't be a Null value in them. You've got NaN though. I can't think of any other type that can't be accessed/created directly in SmileBASIC though, besides char.

Nulls and Nones can exist in non-OOP languages. They exist in C (That's Pure C, not C#, C++ Or Objective-C). In fact, they technically can be accessed in SmileBASIC if you do some tricks with user-defined functions and commands (I can't remember what though, it just happened to somebody else when trying to find out how to use them. I think that it was doing just RETURN in a function instead of RETURN X VALUE)

Can't you get NULL from a simple CHR$(0)? That is NULL, right?

Can't you get NULL from a simple CHR$(0)? That is NULL, right?
That's what is commonly known as a "null character", but it holds no special meaning in SmileBASIC. What we are referring to is a variable or return value that literally holds nothing. Though I'm not sure if there is much use for them because in most cases trying to use them gives an "Uninitialized Variable" error. I think according to some tests I did, you could put a null value as an argument to a command with optional arguments (such as SPCHR) and it acts as an empty argument. This may require some more verification, though.

Strings can be read as arrays of characters. Writing is a different story.
A$="Hello":?A$
Hello
A$[0]="J":?A$
Jello
A$[0]="":?A$
ello
A$[0]="E":?A$
Ello
A$[0]="He":?A$
Hello
The biggest result here that I can see is that the statement A$=RIGHT$(A$,LEN(A$)-1) (which appears in a project I'm currently working on) can be replaced with A$[0]="". EDIT: Actually, the biggest result is that I can test the first character of A$ and at the same time remove it from the string, with SHIFT(A$).

Did a little experiment and elements of string arrays are also treated as arrays themselves. For example:
DIM CH$[5]
CH$[0]="HELLO"
?CH$[0][0]
Output:
H