By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,084 Members | 1,969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,084 IT Pros & Developers. It's quick & easy.

Return the value between two specified values...

P: 6
Ok...I'm hoping someone has a simple solution for this problem.

I need to find the value between two other values.

For Instance:

the 44 quick brown foxes jumped over 33 fences

and I need to find anything between "brown" and "fences".

So, in this example, the value returned would be: foxes jumped over 33

Hope that makes sense?
Apr 29 '07 #1
Share this Question
Share on Google+
7 Replies


Expert 5K+
P: 8,434
Try using Instr() function to find them, and Mid() function to return the chunk of text. At a guess, you'll also need to use the Len() function to determine the length of your start/stop strings so you can adjust things accordingly.

I'm not going into greater detail, because this sounds suspiciously like a homework assignment, and we do not want to answer those for you.
Apr 29 '07 #2

P: 6
Killer42...

Too funny. Nope...no homework here. (Sheesh...this must have been a really lame question!) I'm trying to learn VB 2005 to use in my business. I am watching training videos online and so far so good. (Used to fool around with QBasic years ago on an old Tandy hooked to a TV :)

Thanks for the help. I had thought about that idea but was thinking there might already be a built in class/function to support this without having to write a large chunk of code....no such luck.

The problem with my code right now using Instr() is that it is case sensitive.

So, it works fine if I am looking for the string "test" in "I took a test".....BUT if I search for "Test" the result is 0.

I've tried every single solution Microsoft has for converting a string to Upper, Lower, etc... but no such luck converting the value of the variable.

Thanks for the help though.
Apr 30 '07 #3

Expert 5K+
P: 8,434
So you'd be looking for a way to convert your text to UpperCASE, then? ;)

I wouldn't say your question was lame, but it did sound a lot like the kind of examples they dole out to people learning VB. Which is probably a good sign, huh.
Apr 30 '07 #4

P: 6
So you'd be looking for a way to convert your text to UpperCASE, then? ;)

I wouldn't say your question was lame, but it did sound a lot like the kind of examples they dole out to people learning VB. Which is probably a good sign, huh.
Ok... I used UCase previously...here is my code:

Expand|Select|Wrap|Line Numbers
  1. Dim s As String
  2.         s = "test"
  3.         Console.WriteLine(UCase(s))
So, I then set a breakpoint and begin stepping through my code. After the line with UCase is executed, and I hover over the variable "s" to get it's value, the popup still shows that the value is "test" ....but not TEST.

Thanks for your patience...Redmond here I come!
Apr 30 '07 #5

Expert 5K+
P: 8,434
Ok... I used UCase previously...here is my code:

Expand|Select|Wrap|Line Numbers
  1. Dim s As String
  2. s = "test"
  3. Console.WriteLine(UCase(s))
So, I then set a breakpoint and begin stepping through my code. After the line with UCase is executed, and I hover over the variable "s" to get it's value, the popup still shows that the value is "test" ....but not TEST.

Thanks for your patience...Redmond here I come!
A function returns a value. It doesn't (usually) affect the values of the parameters you pass to it. So in other words, you are feeding in "test", and it is handing back "TEST" to the WriteLine method. If you want to use the uppercase version of the text for anything, you need to either use the Ucase() function everywhere, or (generally the more efficient method) assign it to a variable. For example...
Expand|Select|Wrap|Line Numbers
  1. Dim s As String
  2. Dim t As String
  3. s = "test"
  4. t = Ucase(s)
  5. Console.WriteLine(t)
This should produce the same output, but you now have both original (s) and uppercase (t) versions of the string to play with.
Apr 30 '07 #6

P: 6
THANK YOU!

Man, why I couldn't find that in the piles of Microsoft Help is beyond me.

Much appreciation for your help.

I'm almost finished with the code and will post for others to benefit from...and probably get some good constructive criticism!

Thanks again.
May 1 '07 #7

Expert 5K+
P: 8,434
Hey, if you want criticism you've come to the right place. :D

Good luck!
May 1 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.