|
I'm trying to validate a string, ie alpha, numerics and some special characters
I'm using something like this
public bool IsAlphaNumeric(String strToCheck)
{
Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9.,-]");
return !objAlphaNumericPattern.IsMatch(strToCheck);
}
but when I want to include whitespace (line break etc) using \s,
the page page breaks and tells me there is a 'Unrecognized escape sequence',
I have tried adding @ sign and 'RegexOptions.IgnorePatternWhitespace' which in theory should do the trick, but does nothing. What do I need to do to make this work.
Kwai
|
|
|
|
|
\\s
---
b { font-weight: normal; }
|
|
|
|
|
i've tried '\\s' already - it compiles okay but when I call the class it returns this error
'parsing "[^a-zA-Z'.,-\s]" - Cannot include class \s in character range.'
kwai
|
|
|
|
|
Try changing position for '\s' class. Something like: [^a-zA-Z\s'.,-]
|
|
|
|
|
A U.S. user reported that when they set a custom short time pattern in regional settings to a 24 hour clock it doesn't display that way in my app.
I use the System.Globalization.CultureInfo.CurrentCulture method to set format for date and time in my app and it works properly for any culture to date.
So I test it out and sure enough, currentculture's ShortDatePattern correctly retrieves a users customized short date, but ShortDatePattern always uses the same format which I guess is the default for the culture which is a 12 hour clock and am pm designation.
This is .net 2.0 by the way.
To test this out yourself:
CultureInfo c = System.Threading.Thread.CurrentThread.CurrentUICulture;
c.ShortDatePattern will always equal whatever was set or overriden in the control panel regional settings, but c.ShortTimePattern will always equal the culture default.
I'm stumped, is this a bug? Is there a workaround? I've searched high and low and found nothing.
|
|
|
|
|
Ahh! Not a bug, an inconsistency. It's amazing how often I seem to find the answer after posting here, despite searching for an hour before that all over the net.
It appears that since the regional settings custom time format has only one box to set a custom time format in (i.e. there is no Long time format or Short time format, only Time format) that .net provides this value in the CurrentCulture CultureInfo objects LongTimePattern property and the ShortTimePattern property defaults to the culture's default setting and is not overriden by the control panel setting.
|
|
|
|
|
So, is it? I heard C# is the evolution of C++ somewhere. I cant seem to find my answer anywhere. Thanks for the help, I'm new to these forums and coding.
|
|
|
|
|
Not really. Bjarne Stroustrup, the creator of the C++ language, recently said that C++ is the the grandparent of C#, in that Java is the parent of C#, and Java's parent is C++.
Java evolved from C++ in that it is a simpler, less powerful but less complex version of C++. C# is closer to C++ than Java, ironically, due to its ability to use pointers, output parameters, and delegates (similar to C's function pointers), whereas Java cannot do those things.
However, C# is not more advanced than C++. Like Java, C# is far less powerful and less complex than C++. All 3 languages really target different areas of software development, comparing them is really apples and oranges once you get beyond their ancestory.
|
|
|
|
|
|
Of course C# is evolution of C++, but C++ is one of the greatest programme language.
=========================================
中国,昆明
|
|
|
|
|
C# is an evolution from several previous languages. Quite a bit Java, lots of C++ and some Pascal, mostly.
In some ways C# is more advanced than C++. The memory management for example is more advanced. It's much more efficient, but also less predictable. It's better for most purposes, but there is still a few applications where you rather want the simple, straight forward, predictable memory management of C++ instead.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
|
It seems you're using the index of the user in the ArrayList as an access key. You may be better off just storing a reference to the user. That way, you can use any type of collection (although an ArrayList is quite suitable) to store the users.
/ravi
|
|
|
|
|
|
Instead of keeping track of an int that's the index into the ArrayList , just keep track of the object (presumably a User ) that you added to the ArrayList . That way you can check if the user is still connected by using Contains() rather than accessing an index that may be invalid.
/ravi
|
|
|
|
|
Oh... So like, assign a user some kind of unique ID or something and pass that to my overridden Contains() ? Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Yes, that will definitely work and is a common way of checking for the presence of objects.
/ravi
|
|
|
|
|
OK, thanks very much!
Windows Calculator told me I will die at 28.
|
|
|
|
|
I looked all over the web for an easy way to read an XML file, with no success. Most places I found used the XmlTextReader.Read() method, which I don't find easy to use if I dont wanna go thru the whole file.
This is what I am looking for. Say I have the following XML file:
<city name="New York">
<population>10,000,000</population>
<growth>1.2</growth>
</city>
<city name="Miami">
<population>7,000,000</population>
<growth>2.4</growth>
</city>
and I would like to access Miami's population element (and get the 7,000,000 string) something like this (I have invent the names of the methods - the final question follows these exampls):
string PopulationOfMiami = xmlfile["Miami"].population;
or perhaps:
string PopulationOfMiami = xmlfile["Miami"].population.value;
or perhaps:
string PopulationOfMiami = xmlfile["Miami"].ElementSon("population").value;
or perhaps:
string PopulationOfMiami = xmlfile.findNameAttribute("Miami").population.value;
I want access to my XML file in a similar form in one of the above fashioned-way. Does anyone know of real methods and class that work like above? I hope I explained myself OK .
Thanks,
Yoni
|
|
|
|
|
|
It looks like you should actually be using XmlDocument, rather than XmlTextReader. That will let you access your data similar to what you're looking for.
XmlDocument doc = new XmlDocument();
doc.LoadXml(yourXML);
String PopOfMiami = doc.SelectSingleNode("/cities/city[@name='Miami']/population").InnerText;
Alternately, you can create an XML serializer, which would give you syntax closer to what you're looking for.
--------------
TTFN - Kent
|
|
|
|
|
Thanks - this looks like what I was looking for. Problem is that I have a problem:
My XML is a file, not a string variable. i.e. this doesn't work:
XmlDocument doc = new XmlDocument();
doc.LoadXml(@"c:\myfile.xml");
String PopOfMiami = doc.SelectSingleNode("/cities/city[@name='Miami']/population").InnerText;
I looked around for a way around this, trying to give LoadXml a XmlReader and XmlTextReader, but nothing. How can I load my XML file and then do the select?
Thanks,
Yoni
|
|
|
|
|
If the XML is in a file use doc.Load(path) instead.
--------------
TTFN - Kent
|
|
|
|
|
Thanks. New problem
I get a "XmlException: '?' is an unexpected token. Expecting white space" exception. doh. Any ideas?
Thanks again,
Yoni
|
|
|
|
|
What does your XML look like?
-- modified at 14:52 Tuesday 12th December, 2006
As in, it's not just the six lines above, is it?
--------------
TTFN - Kent
|
|
|
|