473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Replace Null Characters (ASCII 0) in file

37
Hi,

I have a java code that open and read a file. My problem is the file had null char, that had been saved by flash. This null char represent new line in text.
My question is, how can I replace the null char with the new line tag.

Thanks in advance.
Aug 24 '07 #1
1 7187
Nepomuk
3,112 Expert 2GB
Hi,

I have a java code that open and read a file. My problem is the file had null char, that had been saved by flash. This null char represent new line in text.
My question is, how can I replace the null char with the new line tag.

Thanks in advance.
This does the job:
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args)
  2. {
  3.     char ascii0 = 0; // Characters can be defined by their ASCII value
  4.     char[] hello = ("Here comes a " + ascii0 + "new line.").toCharArray(); // Create a String, which contains an ASCII 0 and convert it to a char array
  5.     System.out.println(new String(hello)); // Print it (just for checking)
  6.  
  7.     for(int i=0;i<hello.length;i++)
  8.     {
  9.         if(hello[i] == 0) hello[i] = '\n'; // If it finds a ASCII 0, it should replace it by a new line character
  10.     }
  11.     System.out.println("\n" + new String(hello)); // Print the result (just for checking)
  12. }
  13.  
Aug 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Nicolas Bouillon | last post by:
Hi I would like to replace accentuel chars (like "é", "è" or "à") with non accetued ones ("é" -> "e", "è" -> "e", "à" -> "a"). I have tried string.replace method, but it seems dislike...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
2
by: John Nagle | last post by:
I'm trying to clean up a bad ASCII string, one read from a web page that is supposedly in the ASCII character set but has some characters above 127. And I get this: File...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.