gettingstarted
[Top] [All Lists]

last occurrence of a character.

To: Getting Started <gettingstarted at lists dot realsoftware dot com>
Subject: last occurrence of a character.
From: Stephen Goodson <sgoodson at sawco dot com>
Date: Tue, 31 Aug 2004 12:24:15 -0400
Delivered-to: gettingstarted at lists dot realsoftware dot com
How do I get the _last_ occurrence of a character in a string.

Getting the First occurrence is:
        Dim first As Integer
        first = InStr("this is a test", "s")     //returns 4

Last might be something like (Pseudo code):

        Dim last As Integer
        last = LastInStr("this is a test", "s")    //returns 13
        // then I could use the Right function
        Dim s As String
        s=Right( "this is a test" , last)   //returns "st"

I don't think there is a function for it. But, I'm sure there must be a way to do it.

Thanks,
Stephen J. Goodson

PS: As I was proofing this email and looking at the LR (Language Reference) I thought of
one way to possibly do this (Pseudo code):

        Dim count as Integer
        Dim s, field as String
        s="this is a test"
        count=CountFields(s, "s")  // should return 4
        field= "s" + NthField(  s ,"s", count ) // should return... "st"
        // But this is a bit... kluge!

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>