Filtering of a string

Posted on 2011-10-12
Last Modified: 2012-05-12
Hi, I have a string
Eg. = 100

I just want the string container1, how can I filter this?
*note this container string might be from container1 till container100

I tried using str=right(..... But have a hard time figuring it out. Hope sone expert can help.

I'm using vb script
Question by:csharp_learner
    LVL 18

    Accepted Solution

    If your string is always in that format, an easy way would be:

    strA = Left(FullString, InStrRev(FullString, ".") - 1)
    strB = Left(strA, InStrRev(strA, ".") - 1)
    ContainerStr = Mid(strB, InStrRev(strB, ".")  + 1)

    You could fool around to use just one variable, but this is probably easier to see.
    LVL 53

    Expert Comment

    Can you explain it a little more because I can't follow completly. Are you're string always the same (with a changin name of the containernumber) ?

    txt = " = 100"
    pos = InStr(1, txt, "container")
    txt = Right(txt, Len(txt) - (InStr(1, txt, "container")) + 1)
    txt = Left(txt, InStr(1, txt, ".") - 1)

    Open in new window

    LVL 51

    Expert Comment

    by:Bill Prew
    Another way to do this is using the Split() function, which will break apart a string into array elements, using a delimiter you specify.  In this case you can break apart at the periods like this:

    strTemp = " = 100"
    strFields = Split(strTemp, ".")
    Wscript.Echo strFields(3)

    Open in new window

    Just keep in mind that the resulting array is zero based, so the first elemnet will be strFields(0).


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now