|
-
Jun 26th, 2003, 07:18 AM
#1
Thread Starter
Hyperactive Member
Parsing a String using Regular Expressions
Gentlemen:
I have this kind of strings coming from the RS232 port into a RichTextBox1. I'm only interested in the numbers right after the equal sign "="
I need to extract this numbers in the same line order shown and place the value into textboxes, each value will go into its own textbox
(there are 110 lines in the final rs232 file). Any idea? I'm using VBNet 2003.
Thanks everyone.
Rs232 file
Sel. 1
Pago = 119
Libre = 0
Test = 0
Desc.= 0
Sel. 2
Pago = 9
Libre = 0
Test = 0
Desc.= 0
Sel. 3
Pago = 322
Libre = 0
Test = 0
Desc.= 0
-
Jun 26th, 2003, 10:12 AM
#2
Frenzied Member
I dont know too much about regular expressions but you might find what you are looking for here. http://www.regxlib.com
-
Jun 27th, 2003, 02:58 AM
#3
Can you try something like this pseudocode?
You may need to truncate result to strip of the carriage return character(s) but I think you may be able to use Strip() to do this.
VB Code:
Dim i as Integer
Dim line as String
Dim result as String
for each line in file
i = instr( line, "=" )
if i <> 0 then
result = mid( line, i + 1 )
'put result into appropriate text box
endif
next line
This world is not my home. I'm just passing through.
-
Jun 27th, 2003, 10:58 AM
#4
Fanatic Member
Simply replace the variable sInput with whatever your variable is named that contains the text you want to extract the numbers from. This will match negative numbers, integers, and reals.
VB Code:
Dim reg As New System.Text.RegularExpressions.Regex("(?<==\s+)-?\d+\.?\d*")
Dim M As System.Text.RegularExpressions.Match
For Each M In reg.Matches(sInput)
Console.WriteLine(M.Value)
Next
I have two simple requests: 1) Use useful and specific topics. 2) Modify your topic to include [Resolved] when you problem has been resolved. Both of these make the bulletin boards more useful and efficient. Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|