What's the most efficient way to pull culture information out of a resx's filename using C#? The solution should also handle there not being culture info in the file name (ie form1.resx). In that case a string assigned "Default" should be returned.
views:
54answers:
2
+2
A:
Your best bet is just using regex:
string ParseCulture(string input)
{
var r = Regex.new('[\w\d]+\.([\w\-]+)\.resx')
// Match the regular expression pattern against a text string.
Match m = r.Match(input);
if (m.Success)
{
return m.Groups[1];
}
else
{
return "Default";
}
}
This gets back a match (with the phrase you're looking for as the match), or no match (which means you should use "Default").
aronchick
2010-04-23 18:32:05
Sorry, I asked the question poorly. I don't know exactly which culture will be there, I just need to grab it if it is between the periods.
Lee Warner
2010-04-23 18:34:49
yep, my regex would work fine for that.
aronchick
2010-04-23 18:35:57
+4
A:
This seems like it would work:
string GetCulture(string s)
{
var arr=s.Split(".");
if(arr.Length>2)
return arr[1];
else
return "Default";
}
Blindy
2010-04-23 18:34:01