• Two Easy VB.Net Questions
    3 replies, posted
First question is, is there a simple way to take a string, and move each characters ASCII value, but keep it in the alphabet? I wrote one, and it ended up encrypting into crazy characters. Also, if I were to load an XML document with the variable 'xmldocument', then load another one on that same variable, will it remove the first XML from memory, and add the new XML to memory? Thanks in advanced :D
Turn string into char array, if it's in bounds do your thing. [code] string Thisisatest = "ascii@#*($*&#@(*$&(ascii"; char[] charArray = Thisisatest.ToCharArray(); for (int i = 0; i < charArray.Length; i++) { if(char.IsLetter(charArray[i])) { // do your shifting to charArray[i] } } Thisisatest = new string(charArray); [/code] It's in C#, but like hell am I coding in VB.
[QUOTE=Skapocalypse;21063323]First question is, is there a simple way to take a string, and move each characters ASCII value, but keep it in the alphabet? I wrote one, and it ended up encrypting into crazy characters.[/QUOTE] I haven't written any VB in about 15 years, so I'm not going to try to give you code, but algorithmically, what you'd do is iterate over the characters in the string and do the following to each: [list] [*]Check whether the character is >= 'a' and <= 'z', meaning that it's a lowercase letter. [*]If it is, subtract 'a' to obtain the character's index in the alphabet (0 for 'a', 1 for 'b', etc.) [*]Do whatever transformation you want on the resulting value, like adding 13 modulo 26 or subtracting the value from 26. [*]Add 'a' again to turn the alphabetic index back into a real character. [*]If it wasn't a lowercase letter, check whether it's >= 'A' and <= 'Z', meaning that it's an uppercase letter. [*]If it is, perform the above steps but subtracting and adding 'A' instead of 'a'. [*]If it's neither a lowercase nor an uppercase letter, then (presumably) leave the character unchanged. [/list] This is assuming that VB lets you do arithmetic on characters; I don't remember whether it does. If not, use a better language. [QUOTE=Skapocalypse;21063323]Also, if I were to load an XML document with the variable 'xmldocument', then load another one on that same variable, will it remove the first XML from memory, and add the new XML to memory?[/QUOTE] Assuming there are no other references to the first XML document (e.g. in other variables), it becomes garbage and will eventually be reclaimed by the garbage collector. You can't make any assumptions about when it will happen.
You both helped :D I'm just coding this in VB. I know C++ and C# as well. VB is just a lot faster for this application. I really appreciate it both of you :)
Sorry, you need to Log In to post a reply to this thread.