Qbasicnews.com

Full Version: Need help underdatnding MID$
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
hi everyone i really need help understanding what the function MID$ and the stament MID$ mean i looked in qbasic help but i didnt understand can somone post an example and explain it in laymens terms...actually stupid people terms? that be awsome. thanks.
ok then.
ahem

MID$ lets you take or put text into other text

hows that.

Heres an example


Code:
SomeString$ = "I like candy"

PRINT SomeString$

PRINT MID$(SomeString$, 8, 5)

MID$(SomeString$, 8, 5) = "Pizza"

PRINT SomeString$

MID$(String$, Position%,Length%)

Length% can be optional
Code:
SomeString$ = "I like candy"

PRINT SomeString$

PRINT MID$(SomeString$, 8, 5)

MID$(SomeString$, 8, 5) = "Pizza"

PRINT SomeString$

what does the 8,5 do and mean?
length and postiion of what?
also is there a command called DELAY?
Heh umm...computerkid14...you're sounding like a n00b...you need to READ those links that were given to you.
Nek: thanks Wink


computerkid:
No, there isn't a command called "DELAY", at least not in QB45.
yes i am a noob. sorry to bother thanks everyone.
Quote: MID$(stringexpression,start[,length])
- stringexpression identifies the string the substring is to be extracted from
- start, a numeric expression that has an integer value between 1 and 32,767, specifies the starting character position of the substring
- length can be omitted if you want all the characters to the right of start

It says here that MID$ is used to retrieve a substring out of a string you specify.
In this function, the first parameter is the string you want to read some other string from. The second paramater is the start of the string you want to retrieve, and the third parameter (optional) is the length of the string you want to retrieve.

E.g. you have a string:
[syntax="QBasic"]A$ = "Hello world!"[/syntax]

Now suppose you want to get the word "world" out of this string, then the input string in MID$ is this A$ variable. Now you should first know the position in the string where this "world" word starts. Just count, the H is 1, the e is 2, the l is 3, the l is 4, ..., the w is 7. So start position is 7. And since the length of the "world" word is 5, you want to retrieve 5 letters from the string. Now you get this:
[syntax="Qbasic"]A$ = "Hello world!"
B$ = MID$(A$, 7, 5)
PRINT B$[/syntax]
If you run this program, you'll see the word "world" displayed on the screen. Try messing with these numbers and you'll know what MID$ does in no time.

Now, there also is a MID$ statement, which means you can change a substring of a string. Suppose in the previous example, you want to change the word "world" to "y'all". You can do it like this:
[syntax="QBasic"]A$ = "Hello world!"
PRINT A$ 'just to check
MID$(A$, 7, 5) = "y'all"
PRINT A$ 'now see for yourself[/syntax]
Note that the substring you want to replace must have the same amount of characters as the substring you replace it with.

Hope it's a little clearer now... Wink

Neo
My definition of noob: someone who thinks he's it. So I guess you're not one of them Smile
Hmn, he edited his message... first he asks for help and now he says goodbye :?

HQSneaker: a n00b may be... but a newb is just someone who is new to a specific area he isn't yet familiar with.
Pages: 1 2