Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have no idea where to start with this project, I don't want to simply convert a set of numbers over to the written equivalent of the number i want to take a set of numbers and convert the numbers into a written text and vice versa. I want to be able to take a document and convert it into a number or set of numbers and have the program be able to recreate the document with 100% accuracy. How do i convert a full bodied text to and from a number or set of numbers?
Posted
Comments
Sergey Alexandrovich Kryukov 14-Feb-11 17:17pm    
First, it needs more clear explanation, second, where is your effort?
--SA
Praveen Kumar Upadhyay 15-Feb-11 4:02am    
please elaborate your question more, give an example of what you want

" I want to be able to take a document and convert it into a number or set of numbers ... "
I'm not sure you know how anything that is stored or manipulated on a computer is handled internally. Anything processed on a computer is expressed as a single, a tuple or even a stream of bytes. Since a stream of bytes can be considered as an ordered set of numbers in the domain [0..255]all you need to to is open the document as a stream (BinaryReader maybe) and read it into an appropriately dimensioned byte array.
There's your set of numbers for you. (Writing that back to disk or memory goes equally well)

I'm pretty sure that is not what you had in mind, but since you haven't stated proper requirements I gave you a solution that fits your question. If you want something else please refine your question.

Cheers!


@SA: Dont' hit me too hard :)
 
Share this answer
 
Comments
Nish Nishant 14-Feb-11 17:38pm    
Not sure if this is what the OP wants, but it gets my 5. I wonder what the OP means by "work of art".
Manfred Rudolf Bihy 14-Feb-11 17:53pm    
I'm most certain that this is not what OP wanted, but as I already wrote in my "answer": If OP thinks it doesn't fit his requirements I invited him to reformulate his question. :)
fjdiewornncalwe 17-Feb-11 8:53am    
Isn't all your code a "work of art"... I know mine is... :) (tongue firmly planted in cheek)
Nish Nishant 17-Feb-11 8:54am    
Well yeah, for a very loose definition of "art" :-)
Sergey Alexandrovich Kryukov 17-Feb-11 19:36pm    
"ASCII Art"?! Please see my answer.
--SA
Since you are taking about "Convert a number(s) into text or work of art"

To convert text to a "Work of Art" you could always consider postscript[^] or Scalable Vector Graphics[^] or even XAML[^]

There are quite a number of similar options available here[^] if you look at the Vector graphics and 3D graphics sections.

If you just want to display numbers from a file as text, the other answers should suffice.

Regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Feb-11 19:33pm    
Reasonable answer, my 5.
Nobody knows what is that...
--SA
Sergey Alexandrovich Kryukov 17-Feb-11 19:34pm    
Wait a minute! Could it be "ASCII Art"?
One more idea... Please see my Answer.
--SA
I think, nobody could figure out what are you trying to make.
All of a sudden, I get a guess: could in possibly be so called "ASCII Art"?!

There are good number of sources, see:
http://en.lmgtfy.com/?q=ascii+art+generator[^].

—SA
 
Share this answer
 
From number to string

double myNum = 34.43;
string strMyNum;
strMyNum = myNum.ToString();
_____


From String to number

string strMynum = "34.43";
double myNum = double.Parse(strMynum);
 
Share this answer
 
Comments
Manfred Rudolf Bihy 14-Feb-11 17:33pm    
Where's the part about the conversion of a document OP specifically asked about?
MacIntyre 14-Feb-11 17:45pm    
I was writing my answer before the doc OP was brought up. Never heard of it..
Manfred Rudolf Bihy 14-Feb-11 17:51pm    
There is no revision of the question so OP already had the question posted before you could have answered it. Don't try to fool me.
Nish Nishant 14-Feb-11 17:54pm    
Cornered! :-)
Manfred Rudolf Bihy 14-Feb-11 17:58pm    
:grins smugly:
I am guessing you want to take some text that has

"twelve thousand nine hundred and fifty seven"

and convert it to

12,957

for example.

If this is the case, then your starting point would be to split the string into some collection (List<string> or an array)
Next, parse it starting at the right - i.e. the lowest significant digit.
Take this word (seven in the example) and obtain the numeric equivalent. to do this you will need a dictionary of some sort containing pairs ("One", 1) ("Two", 2) of stings and integers.
Then move on to the next most significant word (fifty).
Perform a similar process.
Keep going.

You obviously need to take into account words that can be ignored ("and") and cases where you may get a single digit or a number (e.g. if the example was 12,950 your right-most word is "fifty" which you must take as the number 50 and not the digit '5' as it would be in the previous example.

You also need to check for words like hundred, thousand, million etc, in context (i.e. you need to know where you are in your output in order to determine the meaning of that word.

e.g. "Three hundred thousand"

You're looking for the least sig digit. You find "thousand" so you know that you need to provide the 'first' three digits yourself (000). When you next get the "hundred" you know you need to provide the next 2 digits (00). When you finally get the 3, you just use it. An lo! 3 00 000 or Three Hundred Thousand.

I really hope that's what your question was asking!

If you are certain of the formatting of the text, and have a limited range of numbers, you could just be lazy, and have a collection of every number written out, with its equivalent in digits!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900