Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String Commands
#1
Hi-
I am just learning...
I am trying to write a program using string commands.
Specifically trying to identify number of words and spaces in a sentence
Reply
#2
Alright.
We can't help you, unless you tell us what problem you're having.
Do you want a list of common string functions? If so, here:
STR$(numeric-variable) - Takes a numeric variable, and returns a string with those numbers in it. For instance, if numeric-variable had 123 in it, the string would be "123".
RIGHT$(string-expression,numeric-expression) - Takes the string in string-expression, and returns the right most numeric-expression number of letters.
LEFT$(string-expression,numeric-expression) - Same as above, except returns the left most numeric-expression number of letters.
The following is taken from QBasic help, on the MID$ function:
Quote:MID$(stringvariable$,start%[,length%])=stringexpression$

- stringvariable$ The string variable being modified.
- start% The character position at which the change starts.
- length% If included, the number of characters being
replaced. The length% is a numeric expression.
- stringexpression$ The new characters.
Hope that helps.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#3
instr and especially mid$ might be useful to you. see the qb help (or the link) to find out what they do

to find the location of every occurance of a space, find instr, and set instr's pointer to the last value it gives until it finds nothing. then record these, and use mid$ to separate the words.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#4
To find out how many spaces or words there are in a string, you have to compare each character in the string with the space (" ") string.

This is really easy... Read up on the MID$ command and LEN command, and use a FOR...NEXT loop to count the spaces.

One point: It don't work for those strings with double spaces. If you can do the first part, try working on this slight problem. I, for one, am interested in a program like this, cos its the type of program that you think "I could probably make it but I can't be bothered" :wink:
Reply
#5
Quote:instr and especially mid$
Why can't I find these links on the homepage? Have I gone blind?
Reply
#6
look at the top where a link says "qboho".

either way, it's qbasicnews.com/qboho .

but all it is is qb's help converted to html. you can get the same thing pressing 'f1' inside qb.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#7
I know, but I don't have access to QB everywhere.
Reply
#8
But you were on the site!!! Check the top of the page, below the QBasicnews title on the right. It will say Back to QBasicNews.com and below that QBOHO. Or you can click here.
Reply
#9
I was looking on the main page: www.qbasicnews.com
That's why...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)