473,503 Members | 11,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function to strip out matching value? vb Noob

I've got a string that will look like this:

zzz='hello',kkk='goodbye',jpjh='zz7t8d8',mary='Tha nk
You',jane='idontwantthis',somethingelse='nothinghe re'

It will have undefined number comma seperated tokens.

I want to write a VB function that when passed a matching left side
identifier, returns it's assigned value. If none match, returns "Error
No Match"

so myfunction("mary") should return "Thank You"

Thanks for any help or information!

Feb 26 '07 #1
5 1180
On Feb 26, 12:13 pm, "jobs" <j...@webdos.comwrote:
I've got a string that will look like this:

zzz='hello',kkk='goodbye',jpjh='zz7t8d8',mary='Tha nk
You',jane='idontwantthis',somethingelse='nothinghe re'

It will have undefined number comma seperated tokens.

I want to write a VB function that when passed a matching left side
identifier, returns it's assigned value. If none match, returns "Error
No Match"

so myfunction("mary") should return "Thank You"

Thanks for any help or information!
hmmm you could split the string based on the comma, then go through
each item that results from the split and split again on the "=". You
could use these splits to build a hash table where the left side of
"=" is the key and the right side is the value.
Then your function would take the key, look it up in the hash table
and return the value.

Feb 26 '07 #2
jobs wrote:
I've got a string that will look like this:

zzz='hello',kkk='goodbye',jpjh='zz7t8d8',mary='Tha nk
You',jane='idontwantthis',somethingelse='nothinghe re'

It will have undefined number comma seperated tokens.

I want to write a VB function that when passed a matching left side
identifier, returns it's assigned value. If none match, returns "Error
No Match"

so myfunction("mary") should return "Thank You"

Thanks for any help or information!
I would create a regular expression from the identifier. The identifier
"mary" would give the regular expression "(?:^|,)mary='([^']*)'".

Dim data As String =
"zzz='hello',kkk='goodbye',jpjh='zz7t8d8',mary='Th ank
You',jane='idontwantthis',somethingelse='nothinghe re'"
Dim identifier As String = "mary"
Dim pattern As String = "(?:^|,)" & Regex.Escape(identifier) & "='([^']*)'"
Dim match As Match = Regex.Match(data, pattern)
Dim value As String
If match.Groups.Count = 2 Then
value = match.Groups(1).Value
Else
value = "Error No Match"
End If

--
Göran Andersson
_____
http://www.guffa.com
Feb 26 '07 #3
Thank you that's perfect!
Feb 26 '07 #4
hi.

sorry, my requirements are slightly different than expected. Not sure
if the spaces or special characters are the problem, but I need it
find identifiers like this as well:

Filename = 'd:\jcp\hellocpm.txt', Filename2 = 'd:\jcp\hellocpm.txt'

its reporting match group = 1 and not 2.

Thanks.

Feb 26 '07 #5
On Feb 26, 3:30 pm, "jobs" <j...@webdos.comwrote:
hi.

sorry, my requirements are slightly different than expected. Not sure
if the spaces or special characters are the problem, but I need it
find identifiers like this as well:

Filename = 'd:\jcp\hellocpm.txt', Filename2 = 'd:\jcp\hellocpm.txt'

its reporting match group = 1 and not 2.

Thanks.
please disregard this.. I figured it out. thanks.

Feb 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5065
by: Vaca Louca | last post by:
Hello, My setup: Debian sarge on dual Pentium 4. g++ 3.3.5-3. (the other system is Windows XP with MS Visual Studio .NET 2003) I have an auto_array<T> template (based on a template taken from...
5
5943
by: JackM | last post by:
I'm trying to write a function that will trim and strip new line character returns from submitted $_POST values. Does this look serviceable? function trim_data($formdata) { foreach ($formdata...
4
22979
by: Lauren Wilson | last post by:
Hi folks, We have a need to replace sub strings in certain message text. We use the Office Assistant to display help and often use the imbedded formatting commands. Those of you who have used...
1
2140
by: KevinGPO | last post by:
I am wondering about what's the best and easiest way to strip trailing whitespace from every single file in a folder, recursively. I want to write a program/script so that you pass in a folder...
16
11200
by: Martin Jørgensen | last post by:
Hi, Short question: Any particular reason for why I'm getting a warning here: (cast from function call of type int to non-matching type double) xdouble = (double)rand()/(double)RAND_MAX;
6
3859
by: bratiskovci | last post by:
1. How do I change the program so that the program does not terminate after completing one conversion. Instead, the program should continue to convert values until the user indicates that he/she...
1
3824
by: wkerplunk | last post by:
Below is what I have build with several different languages. It works great but I need help, I am stuck. When you click on an item in the dropdown autocomplete div it does a mousedown function...
27
1692
by: idoerg | last post by:
Hi all, I am running Python 2.5 on Feisty Ubuntu. I came across some code that is substantially slower when in a method than in a function. ################# START SOURCE ############# # The...
1
1299
by: adamjblakey | last post by:
Hi, I have the following function which does not strip everything i need. function StripAll($value) { $value = preg_replace('/+/', '', $value); $value =...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.