|
I was aware of that, and that is exactly why I sort of explained the pattern. He could use three characters from it and get any string that starts with a digit.
BTW: it also applies to your approach, at least the one you posted originally.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
modified on Thursday, May 26, 2011 6:57 PM
|
|
|
|
|
If he is just checking for a positive first digit, regex is a horrible, expensive solution anyways... just check '0' <> '9', not like they are going to invent new digits any time soon.
|
|
|
|
|
I agree. And that is one reason why I seldom use regex, the other is readability isn't great.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
I definitely use it when I need to scrub more complex input, but for a single digit? waaay overkill... thats like using a sledge hammer (no pun intended) to hang up a picture.
|
|
|
|
|
I use them for matching or manipulating strings in non-trivial manners, for example parsing a command line into parameters or extracting information out of HTML source. They may not be particularly readable but they're better than 10 lines of code for the same job. That said, I absolutely agree that a regex for this is ridiculous.
|
|
|
|
|
^[0-9].*$ should do it!
Cheers!
|
|
|
|
|
I don't want to be picky, but when the string contains a \n it will never match. Why didn't you stop at
^[0-9]
?
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Correct!
But to be honest, I agree with Sledgehammer on this: Regex for checking one character is overkill!
Cheers!
|
|
|
|
|
As others have pointed out, regex is massive overkill for this. Try
if(s.Length == 0) return neither;
else if(s[0] == '-') return negative;
else if(s[0] >= '0' && s[0] <= '9') return positive;
else return non-numeric;
Return values are probably an enum or conditions on other bits of code to run. This relies on the numbers being in the character set in order and contiguously, which is true in every encoding I'm aware of.
|
|
|
|
|
I need to scrape a website. The information is stored in SQL and is sent in response to a javascript on the web page. I can use the WebResponse to download the original page source and formulate the necessary java script. Is there a way to execute the javascript using System.Web objects? I tried using automation to create an instance of IE but the new version of IE (9) creates response windows which require manual intervention.
I would like to do something like
<pre>
write(javascript:window.open(document.getElementById('ReportViewerControl').ClientController.m_exportUrlBase, '_self'))
</pre>
Thx
Mark Jackson
|
|
|
|
|
If I understand this right, you want to take a page source and execute JS within it to extract data?
Website scraping is a specific thing for each site, whatever you do, so I recommend that you instead parse the JS (it's almost certainly automatically generated and therefore easy to automatically decompose) to get the data. A regex ought to be able to do that for you. Executing arbitrary JavaScript could produce surprising or even malicious results.
Also, you should check that automated scraping doesn't violate the terms of use of the website, particularly if the content you are scraping is not visible without an account.
|
|
|
|
|
I have 3 separate lists of objects, all containing the same properties:
List<SalesTeamNorth> teamNorth;
List<SalesTeamSouth> teamSouth;
List<SalesTeamEast> teamEast;
Is there a way to merge these 3 lists into a single list (i.e. "List<AllSalesReps> allReps")? I was able to figure out how to merge 3 lists of the same object but not 3 lists of different objects.
For most of my application, it's beneficial to keep these 3 objects separate, however there's one part in which having them merged into a single list object will save me from using lots of repetitive code.
Thanks.
|
|
|
|
|
Do they all share something like a base class, or even better, an interface? If they do, just use that as your type - the horrible alternative is to maintain it as a List of objects which, quite frankly, is no better than maintaining an ArrayList.
|
|
|
|
|
Even when your SalesTeamXyz classes would inherit from a common SalesTeam class, you wouldn't be able to simply cast a List<SalesTeamNorth> to a List<SalesTeam>, so the three lists have no common ancestor. [fixed angular brackets here].
Now do you really want those three classes? and even if you do, do you need the highly specialized lists? it would probably make more sense to have compatible lists, like so:
List<SalesTeam> teamNorth;
List<SalesTeam> teamSouth;
List<SalesTeam> teamEast;
while you still can store more specialized teams in them (with a risk of making some mistakes).
Here is a complete example:
class SalesTeam {
public string name;
}
class SalesTeamNorth : SalesTeam {
public SalesTeamNorth(int v) { name="N"+v; }
}
class SalesTeamSouth : SalesTeam {
public SalesTeamSouth(int v) { name="S"+v; }
}
public override void Test(int arg) {
List<SalesTeam> teamsNorth=new List<SalesTeam>();
for(int i=0; i<3; i++) teamsNorth.Add(new SalesTeamNorth(i));
List<SalesTeam> teamsSouth=new List<SalesTeam>();
for (int i=0; i<3; i++) teamsSouth.Add(new SalesTeamSouth(i));
foreach (List<SalesTeam> teams in new List<List<SalesTeam>>(){ teamsNorth, teamsSouth }) {
foreach (SalesTeam team in teams) {
log(team.name);
}
}
}
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
modified on Thursday, May 26, 2011 12:43 PM
|
|
|
|
|
Why do you have SalesTeamNorth, SalesTeamSouth and SalesTeamEast objects? Why wouldn't you just have a single SalesTeamMember or whatever object?
|
|
|
|
|
Assuming that SalesTeamNorth, SalesTeamSouth, and SalesTeamEast are all classes inheriting from AllSalesReps, you could do it with LINQ:
IList<AllSalesReps> allReps = teamNorth
.Cast<AllSalesReps>()
.Concat(teamSouth)
.Concat(teamEast)
.ToList();
|
|
|
|
|
Agreed.
|
|
|
|
|
You could put everything in one class and add a property "category" eg. With LINQ you could then easily split the one list into the three you want.
Just a quick idea.
V.
|
|
|
|
|
As others have said, there is no obvious reason why you should need a separate class for different groups of sales personnel. If they all have the same properties, and they are all semantically representing the same concept (a salesman), they are actually the same class.
You can't merge lists of different classes. That's an additional incentive for you to rationalise this into being all one class.
|
|
|
|
|
Hello All gurus in C#
Currently I'm developing add-ins for MS Outlook 2007
the idea is, I want to protect my file with some kind of encryption
before attach it into my email.
I have created Outlook form region that applies for Inspector in composing mode and reading mode,
so the add-ins will only appears in composing new mail and appears in reading mail.
I faced some problems, like
1) I cannot attach file programmaticaly to the current Composing Mail Windows
2) I cannot extract file programmatically from the current Reading Mail Windows
I've tried to modify some code from MSDN, but I stuck in the middle
using Office = Microsoft.Office.Core;
using Outlook = Microsoft.Office.Interop.Outlook;
private void button1_Click(object sender, EventArgs e)
{
Outlook.MailItem MyMail = Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
OpenFileDialog attachment = new OpenFileDialog();
OpenFileDialog.show();
if (attachment.FileName.Length > 0)
{
MyMail.Attachments.Add(attachment.FileName, Outlook.OlAttachmentType.olByValue, 1, attachment.FileName);
}
}
Thanks
|
|
|
|
|
Hi,
as the title suggests, I get the following error:
Failed to open XML parser COM object. C:\Program Files (x86)\Microsoft XDE\1.0\WM7_skin.xml
Error while processing skin file C:\Program Files (x86)\Microsoft XDE\1.0\WM7_Skin.xml
View element is either missing or invalid.
System is Windows 7 64 bit with Visual Studio 2010.
Didn't find any useful advice in the Net. Any idea here maybe?
Thanks...
|
|
|
|
|
Do you have the SDK installed? Perhaps reinstalling it will help.
Also, this question would have been better posted in the Mobile forum as it deals with Mobile development rather than C# in general
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I', soory about that, I didn't know there was an extra forum devoted to Mobile development...
As far as the SDK concerns, well I installed the Windows Phone Developer Tools, to be more precise the machine did it, as I had to use the online installer, which I hate, but I didn't find a "normal" installation file to download. Shouldn't the SDK be included?
|
|
|
|
|
|
That is the web installer and I' ve already done it.
My only hope is to try the Windows Phone Developer Tools 7.1 Beta, although something keeps telling me that it will not help and maybe I 'll get problems into running VS afterwards (it happened already once during my previous efforts). Thanks anyway...
|
|
|
|