Results 1 to 6 of 6

Thread: CSV file from a string

  1. #1
    Join Date
    Dec 2009
    Posts
    292

    CSV file from a string

    Hello,
    I made a program to retrieve data from another program and would like to store the data in a specified CSV file, the data that I would like to store will be some thing like this
    Timestamp: 2009-01-27 Sensor number: 2 Temperature: 20.56 ° C
    Humidity: 68.84%
    So I separate the data by commas (CSV) that gives me the result, but I do not know how to distinguish the spaces. If someone can help me.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: CSV file from a string

    Hello,
    You can have this option available for you, check whenever the value inserted does not contain commas (if you replace with a dot, this is an example), which would give some thing like this "68.84" instead of "68.84", and therefore there are more worries for you. The spaces do not arise because of problems with the CSV file.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: CSV file from a string

    Hi,
    The above is correct, you will have those problems if you are going to use the above option, I have another alternative for you, try if it works with you, change the separator character, that is instead of the comma you can replace the separate character, you choose this as the character ";" and then tab (which is "\ t") By using this you will not be confused with the spaces in the file. I hope I have correctly answered your question.

  4. #4
    Join Date
    Dec 2009
    Posts
    292

    Re: CSV file from a string

    Hey
    Yes, this answers my question, but a small thing, I have another question for you, how to delete a string within a String? and to change a character by another? I was trying to replace the character places order, but that logic did not worked very well, do you have any other alternative for this? If I get an alternative for this, then my half of the code is done.

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: CSV file from a string

    Hi,
    If you want to replace one character by another, for example "," to "." you do it in this way
    Code:
    exstr = exstr.replace(',', '.');
    If you want to replace several characters, such as "hihi" to "foo", you do it in this way
    Code:
    exstr = exstr.replaceAll("hihi, "foo");
    hope these methods help you in your code. If you have any more queries with this topic then you can ask it and we will try to answer them.

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: CSV file from a string

    Hi,
    If you want simple replacements, that is to say without using regular expressions. You say that the functions do not work, but in my opinion, you have done this
    Code:
    exstr.replace(',', '.');
    that does not works, since a String can not be changed and therefore the methods that perform operations on a String and returns 1, so it does not changes the given parameter.

Similar Threads

  1. Replies: 7
    Last Post: 02-06-2011, 10:06 PM
  2. How to read string from a given text file using C# program?
    By Kasper in forum Software Development
    Replies: 5
    Last Post: 25-02-2010, 10:18 PM
  3. How to write string data to file using java program?
    By Linoo in forum Software Development
    Replies: 5
    Last Post: 21-01-2010, 09:26 PM
  4. Replace text string using batch file
    By jean-paul martell in forum Operating Systems
    Replies: 2
    Last Post: 23-06-2009, 01:18 PM
  5. Find any file containing a string?
    By Calab in forum Vista Help
    Replies: 15
    Last Post: 06-11-2008, 03:56 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,559,157.28754 seconds with 16 queries