|
Why do I get a dejavu feeling here? Oh yeah, Q&A
|
|
|
|
|
And how about implementing IComparer and using that custom comparer?
Then your compare implementation will need to 'translate' words to ints and then just compare the ints?!?!?
Sounds plausible?
Check this:
http://stackoverflow.com/questions/11278081/convert-words-string-to-int[^]
and
[^]
Cheers
“The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser men so full of doubts.”
|
|
|
|
|
It's not that difficult. Be a programmer fer crap sake:
public class IntList : List<decimal>
{
public decimal NumericValue
{
get
{
DoMath(100);
DoMath(1000);
DoMath(1000000);
DoMath(1000000000);
DoMath(1000000000000);
decimal value = 0;
foreach(decimal item in this)
{
value += item;
}
return value;
}
}
private void DoMath(decimal value)
{
int index = this.IndexOf(value);
if (index >= 1)
{
value *= this[index-1];
this[index] = value;
this[index - 1] = 0;
}
}
public int IndexOf(decimal value)
{
int index = -1;
for (int i = 0; i < this.Count; i++)
{
if (this[i] == value)
{
index = i;
break;
}
}
return index;
}
}
public static class NumberTranslator
{
private static IntList values;
public static Dictionary<string, decimal> numbers = new Dictionary<string, decimal>()
{
{"ZERO", 0},
{"FIRST", 1},
{"ONE", 1},
{"SECOND", 2},
{"TWO", 2},
{"THIRD", 3},
{"THREE", 3},
{"FOUR", 4},
{"FIF", 5},
{"FIVE", 5},
{"SIX", 6},
{"SEVEN", 7},
{"EIGH", 8},
{"NINE", 9},
{"TEN", 10},
{"ELEVEN", 11},
{"TWELF", 12},
{"TWELVE", 12},
{"THIRTEEN", 13},
{"FOURTEEN", 14},
{"FIFTEEN", 15},
{"SIXTEEN", 16},
{"SEVENTEEN", 17},
{"EIGHTEEN", 18},
{"NINETEEN", 19},
{"TWENTY", 20},
{"THIRTY", 30},
{"FOURTY", 40},
{"FIFTY", 50},
{"SIXTY", 60},
{"SEVENTY", 70},
{"EIGHTY", 80},
{"NINETY", 90},
{"HUNDRED", 100},
{"THOUSAND", 1000},
{"MILLION", 1000000},
{"BILLION", 1000000000}
};
public static decimal Translate(string text)
{
text = text.ToUpper().Trim();
string trimChars = "TH";
text = text.Replace("TY", "TY ");
text = text.Replace("-"," ").Replace("_"," ").Replace("."," ").Replace(",", " ");
if (text.EndsWith(trimChars))
{
text = text.TrimEnd(trimChars.ToArray());
}
text = text.Replace(" ", " ");
values = new IntList();
string[] parts = text.Split(' ');
foreach (string numberText in parts)
{
if (numbers.Keys.Contains(numberText))
{
values.Add(numbers[numberText]);
}
else
{
throw new Exception("Not a number (might be spelled wrong)");
}
}
return values.NumericValue;
}
Usage:
decimal value = 0;
value = NumberTranslator.Translate("twelfth");
value = NumberTranslator.Translate("First");
value = NumberTranslator.Translate("One Hundredth");
value = NumberTranslator.Translate("five thousand seven Hundred thirtysecond");
I think that's a fairly complete solution.
".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 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
but if they were a programmer then this would be a programming question and they would be crucified for posting here
usually by you lol
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
I honestly can't recall the last time I crucified someone for posting a programming question in the lounge. Hell, I've barely been on the site since 2012...
".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 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
yes but the reputation remains
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
Bergholt Stuttley Johnson wrote: but the reputation remains Without Enkidu there would be no Gilgamesh Epic, Without Sancho Panza no Quixote, without Satan, no Paradise Lost, etc.
If we didn't have a need for an Eastwood/Norris figure, we wouldn't create one; of course, the protagonist, in this case, is self-recruited for the part.
I think JSOP is doing a bang-up job, and his technical-foo is satisfyingly killer
cheers, Bill
«I'm asked why doesn't C# implement feature X all the time. The answer's always the same: because no one ever designed, specified, implemented, tested, documented, shipped that feature. All six of those things are necessary to make a feature happen. They all cost huge amounts of time, effort and money.» Eric Lippert, Microsoft, 2009
|
|
|
|
|
I wrote an article (and the code I previously posted in this thread is broken). The code in the aticle works much better.
Converting Text Numbers to Numeric Values[^]
".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 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Movie Quote Of The Day
He: I have more in common with a dog than I have with you.
She: I love dogs, I've always loved dogs.
Which movie?
|
|
|
|
|
Bad moon rising
....no wait that was just an awesome song
Hmm i wonder why its doing that......ARGHS NO STOP, ROLLBACK ROLLBACK...F*** That's how i learned to "Always Backup"!!
Dogs are man's best Friend,
Cats are man's adorable little serial killer
|
|
|
|
|
My earth, my puppy and me!
DAAAANG! i can't imagine something funny besides the correct title -.-
...
if(this.signature != "")
{
MessageBox.Show("This is my signature: " + Environment.NewLine + signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|
|
101 Dalmations
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
|
very witty
|
|
|
|
|
I thought it would fit very well for your movie quote, but somehow I don't think its absolutely correct
|
|
|
|
|
Marley and Me
OT - The dog dies.
veni bibi saltavi
|
|
|
|
|
Where's today's CCC, Sir?
Your time will come, if you let it be right.
|
|
|
|
|
I had a small FUBAR with my network and I needed to do a bit of kicking the boxes and rebootarama
veni bibi saltavi
|
|
|
|
|
The Interview
Some men are born mediocre, some men achieve mediocrity, and some men have mediocrity thrust upon them.
|
|
|
|
|
It would seem to me that there is a joke in there somewhere about Paris and doggy style, but since this is the Lounge and not the Jokebox, I think I ought to just leave it alone...
Anything that is unrelated to elephants is irrelephant Anonymous ----- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944 ----- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
Johnny J. wrote: Paris and doggy style
Paris Hilton? Seen that movie, not much dialogue in it to quote from though!
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
|
Had a Carrera-Servo and was fascinated that it was possible to steer and change tracks within the race. Had several bada** sessions with my dad
Now they come up with this high-tech stuff[^].
I feel older now...
if(this.signature != "")
{
MessageBox.Show("This is my signature: " + Environment.NewLine + signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|
|
Buy the toy and feel younger.
|
|
|
|
|
I feel older every second of every day!
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
|
|
|
|
|