Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / text string question...

Author
Message
simonuk74
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location:
Posted: 4th Nov 2002 23:11
if I have a string, A$="any help is great please!", for example, how would I pick out and store the words seperatly in an array ?

heres what I have so far, but I cant get it to work properly

A$="I cant work it out "
A_len=len(A$)
dim words$(999) : rem MAX words in any string
word=1
letters=0

for B=1 to A_len
inc letters,1
word$=right$(mid$(A$,B),letters) *****
words$(word)=word$
if asc(mid$(A$,B+1))=32
letters=0
inc word,1
endif
next a

for C=1 to 10
set cursor 100,20*C
print words$(C)
next p


the problem I have is with the line `****`.
what I want it to do is count up the string, and add 1 to `letters`, when it finds a space in the string ( asc 32 ) , I want it to create a string from the last `SPACE` to the one its on. It finds the last space by resetting `letters` each time it finds a space.
I just cant figure out how to correctly deffine the start and end of the string to be created.

any suggestions are welcome !
Simon
Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 5th Nov 2002 00:31
I hope this will do



"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
simonuk74
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location:
Posted: 5th Nov 2002 00:54
ABSOLUTLY BRILLIANT!!!!!
thanks a lot!


Simon

Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 5th Nov 2002 03:42
Hmmm, just had a thought. The above example does not take into account if there are extra spaces between words or filtering out any unwanted characters like commas, full stops, etc.

So after a rewrite I made a function for you. I hope it works OK in your version of DB, I`m using DBPro so I hope it does.

syntax is:
Return Integer = ReadWords(s$, filter$)

Where s$ is the sentance to be processed and filter$ contains characters you dont want.



"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 5th Nov 2002 04:11
Whoops! Sorry, the function should idealy be like this:





The part that does the filtering was not placed correctly.

"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
ironhoof
21
Years of Service
User Offline
Joined: 3rd Sep 2002
Location:
Posted: 5th Nov 2002 19:10
Just create a spool, PARAM spools are not too tough, treat as dose a script language treats parameters.

Go to the darkbasic code base see if you can find my old string library, A SIMPLE ALL SYMBOL DIVIDABLE PARAMSPOOL.



-----\
There was a man on the stairs that wasn't there.
He wasn't there agian today I think he's from the CIA.
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 6th Nov 2002 00:40
interesting how many crys for text line editors, be interesing to see how many however actually end up with Rich Text editing thou

Anata aru kowagaru no watashi!
TheCyborg
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 6th Nov 2002 22:31
Easily Confused Wrote:
"I hope it works OK in your version of DB..."

I testet it in DB classic 1.13.... and it worked .

TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.
Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 6th Nov 2002 23:50
Thankyou, nice to know

"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
simonuk74
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location:
Posted: 16th Nov 2002 20:27
Thanks all for your help on this, I have what I need now,
( well it works for the database I`m writing. )

I wonder also...
( various questions - just for some ideas )

is there an easy way fo editing a data string ?
for example, .
data 1,2,3,4,5,6
can I add to it ?
data 1,2,3,4,5,6,user input,user input,user input??

and ( I havent tried this yet - just a question off the top of my head ) - can you count how many items are in a labeled data string?
so all-in-all, is it possible to alter the contents/size of a data string and keep track of its size?
would this be done with an array ?

can you alter the size of an array ? - I have figured out how to fill up blank spaces in an array..
so if there is an array with 10 entries, but item 2,5&7 are empty, all the other data will move `up` the array to fill the empty spaces,
but how would I remove empty spaces at the end of the array, by effectivley changing the arrays size?

Simon

simonuk74
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location:
Posted: 16th Nov 2002 20:31
Oh, I dont really NEED all those answered, as I havent even tried some of them myself, just some ideas that some ppl may like to know

simon

Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 17th Nov 2002 18:10
This is one approach to your array resize problem.



Hope this helps

"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
Zooker
21
Years of Service
User Offline
Joined: 27th Oct 2002
Location: United States
Posted: 24th Nov 2002 20:01
Easily Confused

I copied your snippet down for future reference. I hope you don't mind,Zooker!

Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 25th Nov 2002 03:50
Be my guest

"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)

Login to post a reply

Server time is: 2024-03-28 15:01:05
Your offset time is: 2024-03-28 15:01:05