We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › how do I put some new text in a string
Page Index Toggle Pages: 1
how do I put some new text in a string? (Read 325 times)
how do I put some new text in a string?
Aug 9th, 2006, 2:56am
 
Hi,
how do I put some new text into a string? I looked at the string example, but I couldn't figure out how to replace HELLO with "there" - the way I do it here is pretty complicated - I'd rather replace a string with another string, than with characters ...

Here's the code:

textFont(avenir_medium, txtSize[0]);
     fill(r[0], g[0], b[0], a[0]);
     String hla1 = "there";
     text(hla1, 0, 0);
     hla_[0] = textWidth(hla1);

//this doesn't work:
     char data[] = {'H', 'E', 'L', 'L', 'O' };
     String hla1 = new String(data);
Re: how do I put some new text in a string?
Reply #1 - Aug 9th, 2006, 8:15am
 
It's quite easier than you think:

Code:

String s="hello";
println(s);
s="Good Bye";
println(s);
s=s+" and Hello";
println(s);


Prints:
hello
Good Bye
Good Bye and Hello
Page Index Toggle Pages: 1