Loading...
Logo
Processing Forum
So I basically have a system set up that's reading serial data, temperature and humidity, which looks like "65.25 99.1" coming in. I want to transform that to
"Temperature: 65.25 F <br>
Humidity: 99.1 %'
<br> is a new line in HTML, btw. I've tried a few things.. it doesn't seem to let me access each word in the array separately. What do I do?

Replies(8)

Regular expression:
Copy code
  1. String data = "65.25 99.1";
  2. String html = data.replaceAll("([\\d.]+) ([\\d.]+)", "Temperature: $1 F<br>Humidity: $2 %");
  3. println(html);

Thanks! Now the problem is that if I want to saveStrings to a  file, it won't let me because it needs a Strings[] and not a regular non array strings... what is the difference?
The former is an array of Strings, which will be written into different lines in the .txt file...
The latter is a single String.

If you want to save it all to one line, then you could use the following:

Copy code
  1. String[] arrayOfStrings = {html};
  2. saveStrings(path, arrayOfStrings);
Went about it another way. not sure why processing makes it so difficult to go between an array of strings and a single string.......
Copy code
  1. void makeFile() {
      // this next line is just for testing..
      String words = "apple bear";
      // split the words at a space, fills array
      String[] list = split(words, " ");
      // create new string array
      String[] output = new String[1];
      // change the first element in the array just add the two strings with a <BR>
      output[0] = list[0] + "<BR>" + list[1];
      // println(output);
      // save
      saveStrings("temp.html", output);
" Also your example just plain doesn't work for me ;/"
? Click on Copy code, paste in PDE (1.5.1), run. Works for me.

And calsign's example should have been: String[] array = new String[] { yourString };

Copy code
  1. String[] arrayOfStrings = {html};

works for me, am I doing something wrong that I don't know about?
No, calsign, sorry, I was too hasty in my answer late yesterday.  My syntax is for when there is no declaration (no type) before the variable.