Saved Bookmarks
| 1. |
Solve : Count the letters, then generates a number.? |
|
Answer» Does anyone know a code that can count the letters that were enter from a Code: [Select] set /p and then generates each letter into a number, but the number can be converted into the word/phrase again? Well, nevermind I guess. I can't find the file I originally made, LOL. BatchRocks .... If you come asking for knowledge on something, please dont just give up on it like that, as for dont you think you might be back later when you still dont know how to do this and may need to. I personaly would have followed through and given an example even if you dont have the exact file you originally wanted to use to figure out how to make it work for your application, then save a copy of the help you received for a later point when you decide you need it again. This forum is not just for shared solutions that we can code up for you to save you from having to do all the work, but also hopefully you see this as a learning area. Giving up like this frustrates many members. In the future maybe express that it may be of lesser importance because the batch application requirement is gone at this time, but you would still like to figure out how to do this by example so you may learn how it works, and others may learn from your example batch application needs as well.Very wise words, Dave. Batch is so the wrong language for this kind of thing! If you want to stay with the console, with QBasic or any of its clones, it's a "piece of piss" as we say in England. I know the code wizards will say the more modern languages like C or its children are better, but hey! Code: [Select]LINE INPUT "Type a sentence:"; sentence$ Slen=LEN(sentence$) Enc$="" FOR J=1 to Slen Char$=MID$(sentence$,j,1) NUM=ASC(Char$) HS$=HEX$(NUM) Enc$=Enc$+HS$ NEXT J PRINT Enc$ In fact, you could put the loop and everything that is inside it on one line. Like this Code: [Select]FOR J=1 to Slen:Enc$=Enc$+HEX$(ASC(MID$(sentence$,j,1))):NEXT J Isn't that great? Code: [Select]Type a sentence:? Hello world 48656C6C6F20776F726C64 I used FreeBasic, which is, as its name implies, free, and it compiles to .exe files! What more could a budding nerd ask for? http://www.freebasic.net/ I hope I haven't started something... Or do I? VB saves the day! Code: [Select]Dim strInput As String Dim intLetters As Integer = -1 Sub Main() strInput = Console.ReadLine() For i = 0 To strInput.Length intLetters += 1 Next Console.WriteLine("------------------") Console.WriteLine("Number of Letters:") Console.WriteLine(intLetters) Console.ReadKey() End SubVery good, macdad, but it doesn't do this part Quote and then generates each letter into a number, but the number can be converted into the word/phrase againSorry Dave. Thanks for the help. I actually only do Batch Files, and, I passed the project. Thanks for your help, Dias and Mac. DylanQuote from: Dias de VERANO on January 20, 2009, 12:27:09 PM Very good, macdad, but it doesn't do this part ok i see what he wants, its kinda like Word to ASCII code and back to WordQuote from: macdad- on January 20, 2009, 02:32:53 PM ok i see what he wants, its kinda like Word to ASCII code and back to Word Well, he just SAID "numbers", and I just used ASCII because it seemed simpler, but once you have the text converted to numbers then some kind of simple cypher scheme could be arranged (I think that's what he was after) I converted to hex because then every letter of the alphabet converts to a 2 digit hex code which would make conversion back again easier. In fact if you then convert the hex DIGITS say 0>A, 1>B, 2>C etc you'd have a message which would look pretty incomprehensible. If you used a one-time code scheme you'd be fairly secure from AMATEURS as well. Thanks Dias and Mac for FOLLOWING through with this one. Also thanks for link to FreeBasic. Going to have to try that out. That conversion of text to hex was neat, and I added it to my personal geek archive. Quote from: Dias de verano on January 20, 2009, 11:47:03 AM Batch is so the wrong language for this kind of thing! If you want to stay with the console, with QBasic or any of its clones, it's a "piece of piss" as we say in England. I know the code wizards will say the more modern languages like C or its children are better, but hey! Why don't you use Visual Basic 2008 Express. 100% free, and can compile to .exe s as well. I was browsing through this section and I found a script that counts the amount of letters and characters, but only that.Quote from: Helpmeh on January 20, 2009, 04:16:18 PM Why don't you use Visual Basic 2008 Express. 100% free, and can compile to .exe s as well. probably because it requires the .NET framework. Visual Basic .NET is a good language- but it's not Visual Basic(which itself isn't BASIC). if I ever move to .NET I will likely go to C#. I prefer to have direct access to API methods that I need, and wrap them in my own classes. Not some half-assed Microsoft version of a class that covers the API routines in a thin wrapper, like MFC. That Victor, still whittling away at FreeBASIC. It's excellent stuff, too. Once he adds classes, I'll be writing a lot more code in and for it. Quote from: Dias de verano on January 20, 2009, 11:47:03 AM I know the code wizards will say the more modern languages like C or its children are better, but hey! That actually strikes a much reverberated chord- C and C++ and so forth are terrific languages, but- they are a huge pain in the but to debug and test and so forth. QBasic and QuickBASIC make it a lot easier to pumpt out quick chunks of code- especially for string manipulation. String manipulation in C/C++ should require a Surgeon's license. Quote from: Dias de verano on January 20, 2009, 11:47:03 AM In fact, you could put the loop and everything that is inside it on one line. Like thisNow your just showing off |
|