|
Roman Olney wrote: You're a funny guy Paul.
Not really. All I did was to point out that your question was of too general a nature to be answered in this forum.
Read the forum rules, paying specific attention to no.2.
I suggest you post again if you have more specific questions relating to the implementation of your project.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Roman Olney wrote: How do I implement such a system using c# in Visual Studio...?
What do you have so far?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
|
Roman Olney wrote: assigning a coloumn ID to the quote and giving the client a page where they could query that ID and get a copy of their quote...and although that works fine, i want it to be more sophisticated than that.
Why be more sophisticated? That is the general way it is done.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Roman Olney wrote: i want it to be more sophisticated than that.
Really? Try researching the KISS Principle and Rube Goldberg.
Hint: Both have pages on Wikipedia
led mike
|
|
|
|
|
I need to be able to parse the following line, I am not even sure regualar expression are
the best option.
LIC#:ABC123 YRMD:03 MAKE:CHEV BTM :CP VIN :1G1JC12F137230800
into
LIC#:ABC123
YRMD:03
MAKE:CHEV
BTM :CP
VIN :1F1JD12F137230735
And then capture the data after the semicolon.
All can be variable length and there isn't a delimiter
Unfortunately, you also can't depend on the tags having no spaces with the colons (i.e. VIN :, vs YRMD:.
I have been trying to use Grouping to parse this.
I am newish to regular expression and thought maybe I should use them to solve this problem.
Are regular expression even a good fit for this problem?
Any suggestions appreciated.
modified on Friday, March 21, 2008 12:01 PM
|
|
|
|
|
You don't parse with regular expressions.
Try something like this:
private string SplitValue(string str, char delim)
{
string[] parts = str.Split(delim);
return parts[1];
}
private bool Test7()
{
bool result = false;
string original = "LIC#:ABC123 YRMD:03 MAKE:CHEV BTM :CP VIN :1G1JC12F137230800";
string[] parts = original.Split(' ');
if (parts.Length != 7)
{
return result;
}
string license = SplitValue(parts[0], ':');
string yrmd = SplitValue(parts[1], ':');
string make = SplitValue(parts[2], ':'); ;
string btm = parts[4].Replace(":", "");
string vin = parts[6].Replace(":", "");
return true;
}
The code above is based on the string you provided. Since there appear to be spaces in places where there really should be none, you can't really get away with a single split command, so you have to improvise. Yeah, I could have used substring instead of writing another function to split the first three parts, but what the hell, I had time...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Thanks, I would taken a much more difficult approach.
That is embarrassingly simple.
|
|
|
|
|
smesser wrote: Unfortunately, you also can't depend on the tags having no spaces with the colons (i.e. VIN :, vs YRMD:.
Perhaps you could replace " :" with ":" to fix that and make processing easier.
After that, if values don't contain SPACEs then you can split on SPACE and then on colon as mentioned.
Certainly a Regular Expression could be used if the data is regular enough, but why not perform both tasks at once?
|
|
|
|
|
Yes, I had just tried that myself.
That one was looking me right in the face.
|
|
|
|
|
smesser wrote:
All can be variable length and there isn't a delimiter
Unfortunately, you also can't depend on the tags having no spaces with the colons (i.e. VIN :, vs YRMD:.
This is true, which makes parsing strings like that pretty hard. I did however find a pattern in this string, but it doesn't necessarily mean that it holds true for other strings.
Basically it's always a pair of arbitrary strings separated by a colon, sort of like a key/value-pair.
So whenever there's a whitespace left (or also right?) to the colon it doesn't count as a delimiter.
Based on this fact the following regex will work:
[^\ ]+\ *:[^\ ]+
If you want to also disallow whitespaces right to the colon as a delimiter then this will work:
[^\ ]+\ *:\ *[^\ ]+
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Then what use named groups to get your values?
EDIT:
private void Test9()
{
string original = "LIC#:ABC123 YRMD:03 MAKE:CHEV BTM :CP VIN :1G1JC12F137230800";
Regex r = new Regex(@"[^\ ]+\ *:\ *[^\ ]+");
MatchCollection theMatches = r.Matches(original);
foreach (Match theMatch in theMatches)
{
Console.WriteLine(theMatch.Value);
}
}
modified on Friday, March 21, 2008 12:42 PM
|
|
|
|
|
This seems to work
if ( args.Length > 0 )
{
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex
(
@"^\s*LIC#\s*: (?'LIC'.*)YRMD\s*: (?'YRMD'.*)MAKE\s*: (?'MAKE'.*)BTM\s*: (?'BTM'.*)VIN\s: (?'VIN'.*)$"
) ;
foreach ( System.Text.RegularExpressions.Match mat in reg.Matches ( args [ 0 ] ) )
{
System.Console.WriteLine
(
"LIC# = {0} YRMD = {1} MAKE = {2} BTM = {3} VIN = {4}"
,
mat.Groups [ "LIC" ].Value
,
mat.Groups [ "YRMD" ].Value
,
mat.Groups [ "MAKE" ].Value
,
mat.Groups [ "BTM" ].Value
,
mat.Groups [ "VIN" ].Value
) ;
}
}
Dagnabit! Frowny faces?! Who wrote this crap?
I added a SPACE between the : and the ( to solve that little problem, but they should be eliminated from the Regex.
modified on Friday, March 21, 2008 1:52 PM
|
|
|
|
|
PIEBALDconsult wrote: Dagnabit! Frowny faces?! Who wrote this crap?
Paging Chris Maunder.
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop.
-- Matthew Faithfull
|
|
|
|
|
Hum, unless the copy paste messed something up this is not creating a match for me.
|
|
|
|
|
With the SPACE between the : and ( you need to use
System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace
to ignore the extraneous SPACEs, but then the # and everything after it become a comment!
So now I've escaped the the # to \x23 .
Resulting in:
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex
(
@"^\s*LIC\x23\s*: (?'LIC'.*)YRMD\s*: (?'YRMD'.*)MAKE\s*: (?'MAKE'.*)BTM\s*: (?'BTM'.*)VIN\s: (?'VIN'.*)$"
,
System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace
) ;
Whoops, I had left out an asterisk I had meant to include: VIN\s*
modified on Friday, March 21, 2008 2:35 PM
|
|
|
|
|
Quick little edit to get rid of the extra space that was being captured.
^\s*LIC\x23\s*: (?'LIC'.*)\sYRMD\s*: (?'YRMD'.*)\sMAKE\s*: (?'MAKE'.*)\sBTM\s*: (?'BTM'.*)\sVIN\s: (?'VIN'.*)$
|
|
|
|
|
Hey, I was leaving that for the OP to do; I didn't want to solve the whole thing for him.
|
|
|
|
|
Sorry, I was bored and happened to have The Regulator open. At least now I can enjoy the weekend in knowing that I accomplished something today.
|
|
|
|
|
Thanks all, your comments and examples have been very inlightening
modified on Friday, March 21, 2008 6:15 PM
|
|
|
|
|
|
Hi all,
I was just wondering about the following problem. I often write device drivers for various hardware systems. Often I put all that code in a DLL which can be called by another program. Usually I'll need to put in a form somewhere to allow the user to change parameters and settings. Normally this form is in the program that accesses the dll which is all well and good.
Thats all fine, but I got to wondering does anyone know how to put a windows form with buttons and stuff inside a dll? Could I use the forms editor like I would If I was producing an exe or would I have to hard code everything?
Its just that I figured it would lead to a much more modular and potentially better design because all the configuration and control is in one place.
|
|
|
|
|
Just create a C# Class Project and create your forms there, as per normal.
|
|
|
|
|
That was quick! So literally it is just as simple as the process for writing a new exe file then. Thanks I'll have to try it.
|
|
|
|
|
Thanks I tried it and it works just fine.
I needed to simply add a form to the dll class and add a method inside the dll that shows the form. Another program can simply call the method inside the dll to display to form. - Thats just great.
|
|
|
|