Page 1 of 2
RFindString()
Posted: Wed Oct 29, 2003 2:58 pm
by blueznl
search from the end of the string backwards...
equivalents in gfa: instr() and rinstr()
Posted: Wed Oct 29, 2003 3:27 pm
by blueznl
oh well, let's simply code it for now...
Code: Select all
Procedure.l x_countchar(string.s,char.s)
Protected n.l , p.l , l.l
;
; *** counts occurances of character in string
;
n.l = 0
p.l = 0
l.l = Len(string)
While p < l
INC p
If Mid(string,p,1) = char
INC n
EndIf
Wend
ProcedureReturn n
EndProcedure
Procedure.l x_rfindstring(string.s,find.s)
Protected l.l , p.l
;
; *** find a string in another string, starting from the right
;
l.l = Len(find.s)
p.l = Len(string.s)
If l > 0 And p > 0
p = p+l
Repeat
DEC p
Until p.l = 0 Or Mid(string,p,l) = find
EndIf
ProcedureReturn p
EndProcedure
Posted: Wed Oct 29, 2003 3:43 pm
by Psychophanta

Thanks
Just you have bring to my mind a new idea.
I'll make a function in assembler for to perform equivalents in gfa: rinstr().
I will name it: RFindString(). LFindString() already exists, its name is FindString()
And by the way you can find CountChars() and CountStrings() functions made by me in assembler in
www.purearea.net.
You know, you could take it and make a PB userlibrary with all those 3 functions, will you be able to do?

Posted: Wed Oct 29, 2003 5:12 pm
by Fred
Psychophanta: may be you could use name less 'common' for your addon functions because some of them (especially CountString()) will be in a next version and it will invalidate your lib.. Just a tough.
bluenz: 'INC p' is assembly, right ? Why not: 'p+1' ?

Posted: Wed Oct 29, 2003 5:18 pm
by Psychophanta
Ooookay
Note that i use CountStrings() not CountString()

Posted: Wed Oct 29, 2003 10:31 pm
by blueznl
fred, that's an old habit of using gfabasic, it had the following basic commands:
inc a
a += 1
add a , 1
old habits are difficult to kill... will it affect code, as compared to a = a + 1?
psycho, are you sure your countstrings asm function works correctly? i tried it here and got the wrong answer...
currently i'm just dumping my functions in a file, and add x_ to every function name, so fred can update what he wants, and it won't cause me troubles
i always peek into the libraries to see what i can use, but often end up coding something myself... good excercise

but ehm... fred, will rfindstring also show up? or?
Posted: Thu Oct 30, 2003 10:01 am
by Fred
bluenz: I was just pointing out than 'p+1' is like 'p += 1' in C, so it seems shorter than INC p, why not use it. But it's up to you of course

Posted: Thu Oct 30, 2003 10:53 am
by blueznl
readability, my dear man, readability... for some strange reason my mind can *see* basic code, yet perceives c(++) as something foggy, in other words: i have to look at basic to understand it, i have to puzzle to understand c... i have a similar thing with object oriented programming...
and inc c just *looks* better to me than c+=1 or c = c + 1
ah, forgot a variation, gfa also allowed c++

Posted: Thu Oct 30, 2003 11:00 am
by Saboteur
Fred wanted to say that it is not necesary write
you can write simply
Posted: Thu Oct 30, 2003 11:01 am
by blueznl
ooops

Posted: Fri Oct 31, 2003 12:24 pm
by Fred
Do I speak english so badly ?

Posted: Fri Oct 31, 2003 2:29 pm
by Psychophanta
Fred wrote:
Psychophanta: may be you could use name less 'common' for your addon functions because some of them (especially CountString()) will be in a next version and it will invalidate your lib.. Just a tough.
Don't worry, if i make a PB userlib, then i'll rename functions with a prefix, for example "al", but for normal Procedure names, user can name it as is wanted.

Posted: Fri Oct 31, 2003 2:40 pm
by freedimension
Fred wrote:Do I speak english so badly ?

Yes, but you havn't heard me speaking french yet

Posted: Fri Oct 31, 2003 3:16 pm
by blueznl
try dutch for a change
si tu veux, mon ami fred, c'est possible de continuer en francais, mais je te dit, ma connaisance de la langue francais... c'est... le mot propre c'est 'corrode' je pense?
damn, forgot most of my french, i've been working for one and a half year in paris, almost a decade back, and at that time it wasn't a problem at all... hell, i even started swearing at all those bloody foreigners behaving like tourists when using the peripherique

Posted: Tue Jul 19, 2005 1:32 pm
by GeoTrail
I get an error saying p is not a valid operator.
I need to search for a specific character in a word and then search backwards to find the beginning of that word by finding the space infront of it.
Hmm did that make any sence? hehehe