find is like Instr, what's like RevInstr?

Started by axtens, April 08, 2009, 03:40:23 AM

Previous topic - Next topic

axtens

G'day everyone



(find) is like VBScript's Instr(). What is the equivalent for VBScript's RevInstr() wherein one searches for the first occurrence from the other end of the string? (find (reverse))?



Kind regards,

Bruce.

axtens

#1
Quote from: "axtens"What is the equivalent for VBScript's RevInstr() wherein one searches for the first occurrence from the other end of the string? (find (reverse))?


I think I'll have a go at answering my own question.



(set 'reverse-find
(lambda (findThis inThis)
(- (length inThis) (find (reverse findThis) (reverse inThis)) (length findThis))))


and then some demonstrations plus a comparison of what it finds against what (find) finds.


(set 'toFind "dog")
(set 'sentence "My first dog's fleas are on my second dog's blanket")

(println (slice sentence (reverse-find toFind sentence) (length toFind)))
; "dog"
(println (slice sentence (reverse-find toFind sentence)))
; "dog's blanket"
(println (slice sentence (find toFind sentence)))
; "dog's fleas are on my second dog's blanket"


Am I doing okay so far?



Kind regards,

Bruce.

Kazimir Majorinc

#2
I don't know VBscript but it looks OK to me.



I think you are progressing quite good. Are you experienced programmer?
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

axtens

#3
Quote from: "Kazimir Majorinc"I think you are progressing quite good. Are you experienced programmer?


Yes, just not in Lisp. I've been in the IT business in various ways since 1983. At the moment I'm working for http://www.protiumblue.com">The Protium Project and http://www.mytongue.biz">MyTongue as a Software/Test Engineer. I program in a variety of languages, including Ada, assembler, (Visual) BASIC, C/C++, Delphi, Fortran, Perl, Protium, Tcl, and VBScript (and a few lesser known languages.)



Kind regards,

Bruce.