Jump to content

How do i convert a number back into a letter and convert array back into string

asim1999

I have ASCII numbers that i converted from letters from a string and stored in an array. I want to do the opposite and convert the numbers back into letters and merge the letters into the array to a string

How do i do this?

I am using Pascal (Lazarus) BTW.

Current Rig:   CPU: AMD 1950X @4Ghz. Cooler: Enermax Liqtech TR4 360. Motherboard:Asus Zenith Extreme. RAM: 8GB Crucial DDR4 3666. GPU: Reference GTX 970  SSD: 250GB Samsung 970 EVO.  HDD: Seagate Barracuda 7200.14 2TB. Case: Phanteks Enthoo Pro. PSU: Corsair RM1000X. OS: Windows 10 Pro UEFI mode  (installed on SSD)

Peripherals:  Display: Acer XB272 1080p 240Hz G Sync Keyboard: Corsair K95 RGB Brown Mouse: Logitech G502 RGB Headhet: Roccat XTD 5.1 analogue

Daily Devices:Sony Xperia XZ1 Compact and 128GB iPad Pro

Link to comment
Share on other sites

Link to post
Share on other sites

You could create a lookup array where each number corresponds to a letter. So basically implement the ASCII table. (I don't know pascal so I will put this in C++ pseudo code.)

string asciiTable[127]; // Create an array the size of 127 strings.characters[65] = "A"; // Assign each location a string value according to the ascii table.characters[66] = "B";characters[67] = "C";

Then

// Loop for the length of your array. Increment after each loop.for(unsigned int i = 0; i < YourArrayLength; i++){   cout << ASCIITable[YourArray[i]] << endl; // output the value stored in asciiTable at the index of the ascii number stored in your array at the index location of i.}

This isn't a beautiful implementation but should work.

CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to comment
Share on other sites

Link to post
Share on other sites

I don't know Pascal, and I'm not 100% sure what you're asking, but I'll try to help you out anyway.

 

Are you storing the letters as their ASCII value or as the value of itself?

// to ASCII value?'1' = 49// or itself?'1' = 1 

If you're working back and forth between the characters and their ASCII values then the ord and chr functions might be all you need for that part of it.

 

If you want to do the latter then you can accomplish it with the same functions and some basic math.

 

Then it should be pretty easy to build a string from each character.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×