|
Not sure I completely understand your problem. If you have a string and know that the characters before the * is the client, why not just parse until you reach the *? Maybe the way with values.Split isn't the best approach here.
Edit: Just like OriginalGriff suggests (though in a more understandable way I guess..)
modified on Monday, September 21, 2009 8:57 AM
|
|
|
|
|
Is this data format somethng you have come up with, and thus can change? If so, then do. You are potentially giving yourself problems (Google "SQL Injection attack" to see what I mean).
If you can't change it, then I wouldn't bother with Split - iterate over each character in the string looking for your field prefixes in a switch block and handle them that way.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
His idea scared me so much that I dared not comment
So thanks
|
|
|
|
|
I don't see how that applies.
|
|
|
|
|
if you insist on having such a compact (and error-prone) representation, it would be easier to have the separator after the data instead of in front. That way, you can iterate the characters, and collect them until you hit an "separator" at which point you can handle the data you just collected.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
 Mightn't a Regular Expression help?
Edit:
As long as no delimiters are repeated, you can use a Regex to determine the order of the delimiters, then build another Regex to extract the data.
namespace Template
{
public static class Template
{
private static readonly System.Text.RegularExpressions.Regex reg ;
private static readonly System.Collections.Generic.Dictionary<string,string> dic ;
static Template
(
)
{
reg = new System.Text.RegularExpressions.Regex
(
"(\\*|/|\\(|:|\\?|!@|!\\+|\\+|@)"
) ;
dic = new System.Collections.Generic.Dictionary<string,string>() ;
dic [ "*" ] = "(?:\\*(?'Asterisk'.+?))" ;
dic [ "/" ] = "(?:/(?'Slash'.+?))" ;
dic [ "(" ] = "(?:\\((?'LeftParenthesis'.+?))" ;
dic [ ":" ] = "(?::(?'Colon'.+?))" ;
dic [ "?" ] = "(?:\\?(?'QuestionMark'.+?))" ;
dic [ "!@" ] = "(?:!@(?'ExclamationAt'.+?))" ;
dic [ "!+" ] = "(?:!\\+(?'ExclamationPlus'.+?))" ;
dic [ "+" ] = "(?:\\+(?'Plus'.+?))" ;
dic [ "@" ] = "(?:@(?'At'.+?))" ;
return ;
}
[System.STAThreadAttribute()]
public static int
Main
(
string[] args
)
{
int result = 0 ;
try
{
System.Text.StringBuilder sb =
new System.Text.StringBuilder ( "^" ) ;
foreach
(
System.Text.RegularExpressions.Match mat
in
reg.Matches ( args [ 0 ] )
)
{
sb.Append ( dic [ mat.Value ] ) ;
}
sb.Append ( "$" ) ;
System.Text.RegularExpressions.Regex temp =
new System.Text.RegularExpressions.Regex
(
sb.ToString()
) ;
foreach
(
System.Text.RegularExpressions.Match mat
in
temp.Matches ( args [ 0 ] )
)
{
foreach ( string gro in temp.GetGroupNames() )
{
System.Console.WriteLine ( "{0} = {1}" , gro , mat.Groups [ gro ].Value ) ;
}
}
}
catch ( System.Exception err )
{
while ( err != null )
{
System.Console.WriteLine ( err ) ;
err = err.InnerException ;
}
}
return ( result ) ;
}
}
}
|
|
|
|
|
if it works. Will you show one that isolates pieces of data in between two arbitrary delimiters?
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
modified on Monday, September 21, 2009 12:03 PM
|
|
|
|
|
If you insist: "(\*([\w\s]*)|\/([\w/s]*))" works with the first two of the OP prefixes, and even includes the prefix in the grouped item. Horrible isn't it? I will admit it could be used with named groups etc, etc, but it would still be hard to understand, maintain, etc. That's why I didn't suggest it! Yeuch. Regex has it's place: this is not it!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I said "help", not "do it all in one swell foop".
But I'll give it a shot; I have nothing else going on today. 
|
|
|
|
|
They're not exactly arbitrary. This one seems to work:
(?:(?'Delimiter'(\*|/|\(|:|\?|!@|!\+|\+|@))(?'Value'.+?))(?=(\*|/|\(|:|\?|!@|!\+|\+|@|))
(Whoops, no it doesn't... Working...)
Ah, here we go:
(?:(?'Delimiter'(\*|/|\(|:|\?|!@|!\+|\+|@))(?'Value'[^\*/\(\?!@\+:]*))
modified on Monday, September 21, 2009 1:33 PM
|
|
|
|
|
yep. it works:
public override void Test(int arg) {
Regex r=new Regex(@"(?:(?'Delimiter'(\*|/|\(|:|\?|!@|!\+|\+|@))(?'Value'[^\*/\(\?!@\+:]*))");
DoIt(r, @"*A(M!@12?SIMPLE!+5+2/AB:6");
DoIt(r, @"!+5+2/AB:6*A(M!@12?SIMPLE");
}
public void DoIt(Regex r, string s) {
log("");
log("input="+s);
foreach (Match m in r.Matches(s)) {
GroupCollection g=m.Groups;
log(" Delimiter=\""+g["Delimiter"]+"\" Value=\""+g["Value"]+"\"");
}
}
Looks terrible, works fine.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I thought about recommending a regex, but decided that it would be more time and effort to create, test and debug the regex than the equivalant code! As a plus, the code is easier to understand, document and maintain.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
While I understand the frustrations with Regex; in this case I disagree.
|
|
|
|
|
It's a bad design, but this Regex should do it: (?:(?'Delimiter'(\*|/|\(|:|\?|!@|!\+|\+|@))(?'Value'[^\*/\(\?!@\+:]*))
|
|
|
|
|
Does anybody know to work with this junk of help system Microsoft made? I search for "apples oranges cucumbers" and I get 500 results of pages that match ANY of the terms, not ALL the terms as one would normally surmise. No wonder all Microsoft's search tools get a beating from Google. This is less functionality that friggin Notepad! GRRRRRRRRRRRRRR.
^
|_______ and hey, I'm not angry at you ::- D. Maybe it's my fault and I don't know how to use it. Does ANYBODY know???
|
|
|
|
|
Hi,
I've had this WTF moment too and have often wondered why a document explorer search was a lot less precise than I intended it to be.
Q) Is the search term 'apples oranges pears' is equivalent to the term 'apples AND oranges AND pears'?
A) It depends!
Explicit use of the AND operator will give hits that contain all three keywords. The problem when AND is merely implied is that a setting in Visual Studio (Tools..Options..Help..General..Include partial matches in local search results) allows partial matches, in effect allowing 'apples OR oranges OR pears'. Unchecking the box in my VS C# Express 2005 has restored sanity to the world of boolean logic.
Alan.
|
|
|
|
|
*laugh* nice reply Alan. Thanks! It worked! ::- D. Pfew. So it was me who was stupid and didn't investigate well enough the options. Thanks again for showing the way and getting me rid of one of my greatest frustrations EVER.
|
|
|
|
|
I have an executable that is crashing in Release mode for a customer.
I have been reading and have figured out from articles like this:
Do we have to include .pdb files in the final build?
That I need to generate a pdb file for my release and archive it (How to do this: Build, Configuration, Release. Then Project, Properties, Build Tab, Bottom Right in VS2005 find grey button "Advanced...". Press it then set Debug Info drop down list to "pdb-only").
Then when the customer has a crash he needs to email me the .dmp file generated by Windows How to read the small memory dump files that Windows creates for debugging
Now I have to put the two together in Visual Studio and can see where it crashed etc. The problem is I can't find any info on how to actually to do that!
I have to say there are few articles on this subject and it's a mess.
Many Thanks...
modified on Monday, September 21, 2009 4:48 AM
|
|
|
|
|
Hi,
You actually want a Dr Watson crash dump file from your customer. The pdb file allows the data in that dump to be cross referenced to the source code.
Rather than have me possibly mislead you by talking about something I don't fully understand, can I refer you to the Stack Overflow forum where a similar question was raised yesterday. The links to articles by John Robbins of Wintellect look to be very useful.
link[^]
Alan.
|
|
|
|
|
Yes I saw that post and the artiles. Unfortunately the John Robbins' Blogg and his posts are not clear or simple to follow. It took me a long time just to figure out what I wrote in the post above. I have come across no instructions for putting the two files together in Visual Studio. Eg John Robbins "PDB Files: What Every Developer Must Know" fails to even mention .dmp files which the other blog tells us are the key which makes them useful for debugging.
|
|
|
|
|
I'll second any article by John Robbins. He's also written a great book. Debugging Microsoft NET 2.0 Applications[^] (It doesn't matter that it says 2.0, it's still totally relevant)
Once you have the crash dump and the pdbs you can load them into a tool called WinDbg (which comes with Debugging tools for windows[^]) and figure out the cause of the crash. To get the crash dump you'll need a script called adplus (which also comes with debugging tools for windows) which you can run and attach to your app and when it crashes it will create the dump.
Read Johns articles and/or that book and you'll understand a lot more. It's quite a complex topic though so allow plenty of time.
Simon
|
|
|
|
|
|
Half an hour later and I am still trying to figure out what the customer needs to do to collect the dump files. I don't want the customer to have to run Dr Watson all the time in case my app crashes. These windows .dmp files do not look to be enough. This ADPlus seems to be something I need the customer to install in nine complex steps. It's a nighmare.
modified on Monday, September 21, 2009 6:03 AM
|
|
|
|
|
Yes, ADPlus is a nightmare. From the sound of it you would want to use it in crash mode. You run it and attach it and when it detects a crash it creates a dump. I've never used it on a customers machine, I've always been able to replicate the bug on test machines running release mode binaries.
I think Dr Watson might be an easier way of doing the same thing, but to be honest I've never tried it so you'll have to experiment.
Check out this article on configuring Dr Watson to generate crash dumps[^].
Also, just in case you might want to bookmark this article on disabling Dr Watson[^] for when you want to turn it off afterwards.
And here's a description of Dr Watson[^].
Simon
|
|
|
|