|
You could probably do it with String.Split()[^].
The best things in life are not things.
|
|
|
|
|
I believe you are trying to parse a JSON string. If yes then this link might be of some help to you!
|
|
|
|
|
You can parse using JavaScriptSerializer.. This may help to you
string s = "{\"StringC\":"+
"{"+
"\"key1\": \"value\"," +
"\"key2\": \"value\"," +
"\"key3\": \"value\"," +
"\"key4\": \"value\"" +
"},"+
"\"StringD\": \"value\"," +
"\"StringE\":" +
"{"+
"\"key1\": \"value\"" +
"}"+
"}";
JavaScriptSerializer f =new JavaScriptSerializer();
JsonData jsd = f.Deserialize<JsonData>(s);
public class JsonData
{
public Hashtable StringC { get; set; }
public string StringD {get; set;}
public Hashtable StringE { get; set; }
}
|
|
|
|
|
Just so you know, your sample string isn't very consistent. I would think there would have to be a comma after the closing braces.
Beyond that, it seems to me you want to Split on the "{" character, and then the "," character on each of the first split result strings. I would probably write a method that accepted the delimiter character and the string to be split that returned an array of split items.
Regex is not what you want to use - sometimes, you just gotta write the code.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "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
|
|
|
|
|
Try
(.*((\"([\d\w]+)\":)|(\s([\d\w]+) =)))*
The group no 4 contains keys like key or stringC and group 6 contins keys like StringB
EDIT: Of course you need to code
string expr = @"(.*((\"([\d\w]+)\":)|(\s([\d\w]+) =)))*";
var m = Regex.Match(expr);
var group4 = m.Groups[4];
var group6 = m.Group[6];
string[] allStrings = group4.Captures.Select(c=>c.Value).Union(group6.Select(c=>c.Value)).ToArray();
captures now contains strings you need
DISCLAIMER:
1. not tested.
2. use named groups if you want to.
Greetings - Jacek
modified on Wednesday, June 15, 2011 3:38 AM
|
|
|
|
|
In Windows 7 if you go to the Control Panel and then to Region and Language and then to the Locaton Tab there is a dropdown of the locations (countries).
How can I get this list via C#/.NET or even a WINAPI call.
I know about GetCultures and the Telephony registry entries and that I could create a table based off the ISO specification.
GetCultures doesn't return all the countries like Cuba.
Telephony Registry entries are phone country codes so the list is not correct for just countries.
Windows must have this list somewhere since they are using it in the Location Tab.
|
|
|
|
|
I'm not sure it will match the Control Panel, however I would suggest you try CultureInfo.GetCultures()
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.4
|
|
|
|
|
Please go abck and read my original post.
I know what GetCultures does and it doesn't return a valid list of countries. It's missing many countries for example Cuba.
|
|
|
|
|
Oops. Seems like I got distracted and missed half of your post. Sorry.
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.4
|
|
|
|
|
MrSmoofy wrote: doesn't return all the countries like Cuba
How many were you expecting? I thought there was only one country like Cuba.
|
|
|
|
|
There is only one Cuba and GetCultures does not include it.
|
|
|
|
|
Windows probably does, but there is an alternative. Haave a look at GeoNames[^] - they has varaious web services which will provide you with such info, even by country code if you need it.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
I know there are external webservices available but our application will not have access to them as it runs on a private network with no external internet access.
|
|
|
|
|
MrSmoofy wrote: Windows must have this list somewhere since they are using it in the Location Tab.
That doesn't mean that it has to be publicly available. Do you allow other vendors to re-use every resource in your application?
You can find the list in the registry, under this key;
HKLM\Software\Microsoft\Windows\CurrentVersion\Telephony\Country List "Cuba" is number 52 in there
Bastard Programmer from Hell
|
|
|
|
|
Again read my original post. The Telephony Country List is not correct it lists Telephone codes not just countries.
Look at number 5399 "Guantanamo Bay" is not a country
Look at number 800 "International Freephone Service" is not a country
870, 871, 872, 873, 874 are not countries
Also some countries have more then one Telephone code so they are listed twice based on where the town/city/region is in the country.
|
|
|
|
|
MrSmoofy wrote: Again read my original post. The Telephony Country List is not correct it lists Telephone codes not just countries.
I haven't checked the Telephone-codes, I looked in the registry - and Cuba is available.
MrSmoofy wrote: Look at number 5399 "Guantanamo Bay" is not a country
Open up the regional settings and take a look at the "country" list that you wanted - it is also specifying Guantanamo Bay. It's the list that you requested, and no, there is no official list. Here's[^] why.
You're welcome
Bastard Programmer from Hell
|
|
|
|
|
Interesting. My appologies on that one as I didn't see it when I looked.
There are still others on the list that are not countries I guess I will just have to filter them out.
Appears there is an issue on 64bit machines.
string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\Country List\";
RegistryKey countryKey = Registry.LocalMachine.OpenSubKey(keyPath);
countryKey = null
According to Process Monitor it's trying to access the following key which doesn't exist.
HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Telephony\Country List
Also I have found that Servers usually don't have a modem so this registry key doesn't exist.
|
|
|
|
|
MrSmoofy wrote: According to Process Monitor it's trying to access the following key which doesn't exist.
Yes, in short Windows provides separate 32-bit and 64-bit entries. That's described here[^], as well as opening an alternate view.
MrSmoofy wrote: Also I have found that Servers usually don't have a modem so this registry key doesn't exist.
How about exporting the list once from an existing machine to XML or a text-file and use that? Sounds like a good candidate to put in the resources.
Bastard Programmer from Hell
|
|
|
|
|
I wish that was an option.
I've been mandated that we will not be in the business of maintaining the list ourselves. Making it XML does that we would then have to maintain that XML if and when countries change. Microsoft is already maintaining the list. We simply want access to that list.
If I could maintain my own list I would use the ISO list.
|
|
|
|
|
Ah, but you personally may be able to make a few bucks by offering an update service.
|
|
|
|
|
That goes back to it's been mandated that we are not in the business of maintaing a list or webservice providing the list.
Also where the application is installed won't always have internet access to access such a webservice.
|
|
|
|
|
|
Why would I reinvent the wheel. This already exists. It's not an option if the application is installed on servers that do not have access to these services.
|
|
|
|
|
MrSmoofy wrote: do not have access to these services
No Services involved, just send the client a floppy (or whatever ) for a small consideration and your boss is none the wiser.
|
|
|
|
|
Thanks, I'd like to keep my job.
|
|
|
|