[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# Filtering of a string

Posted on 2011-10-12
Medium Priority
255 Views
Hi, I have a string
Eg. Main.store.box1.container1.aiibox.value = 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
0
Question by:csharp_learner

LVL 18

Accepted Solution

Cluskitt earned 1000 total points
ID: 36955052
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.
0

LVL 53

Expert Comment

ID: 36955091
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 = "Main.store.box1.container1.aiibox.value = 100"
pos = InStr(1, txt, "container")
txt = Right(txt, Len(txt) - (InStr(1, txt, "container")) + 1)
txt = Left(txt, InStr(1, txt, ".") - 1)
``````
0

LVL 59

Expert Comment

ID: 36955092
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 = "Main.store.box1.container1.aiibox.value = 100"
strFields = Split(strTemp, ".")
Wscript.Echo strFields(3)
``````
Just keep in mind that the resulting array is zero based, so the first elemnet will be strFields(0).

~bp
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
###### Suggested Courses
Course of the Month18 days, 8 hours left to enroll