954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ASCII to String

Hello, all!

I have a (hopefully) quick question:

I have an array of 128 ASCII characters called blockData[] that I am trying to convert into a string.

for (int i = 0; i < 128; i++){
                blockStuff = inFile.read();
                blockData[i] = blockStuff;
                if (blockData[i] != 0){                    
                String aChar = Character.toString ((char)blockData[i]);
                word += aChar;
                }
            }
            System.out.println("Word is " + word);


My current output is:

Word is null...
lost+foundnagios-3.2.0.tar.gz88nagios-3.2.0$Pi - Dec - Chudnovsky.txt

Now my question is...what is causing those squares in the output? It appears that they are at the indexes where blockData[] == 0.

Any ideas on how I can eliminate them?

Thank you for any input

- Jim

JimD C++ Newb
Light Poster
46 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

Oh I figured it out! It was spots where dataArray[] were set to the values of 0, 1, 19, 20, and a couple others. Thanks!

- Jim

JimD C++ Newb
Light Poster
46 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

Also look at printf which is extremely useful

white feather
Light Poster
49 posts since Apr 2010
Reputation Points: 18
Solved Threads: 2
 

Thank you! I'll check that out!

JimD C++ Newb
Light Poster
46 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You