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 › Using for() to find characters in text.
Page Index Toggle Pages: 1
Using for() to find characters in text. (Read 779 times)
Using for() to find characters in text.
Feb 6th, 2010, 6:51am
 
Hello, i have a source of links that i want to use in Processing, but at the moment, for some reason the links from the source have been escaped with '\''s  
e.g. instead of "ht tp://processing.org/", I get "ht tp:\/\/processing.org\/". (please excuse the spaces, I'm not allowed to post real links yet).

Can I use the looping from the for() with the charAt() or indexOf() functions to go through the links and remove the '\' symbols?
I've had a play around with this, and I know that each time it loops through the letters of the link i need to set a new start/end point to copy the text either side of the '\' mark, but i cant get it working. Is this the approach I should be using? Thanks!
Re: Using for() to find characters in text.
Reply #1 - Feb 6th, 2010, 7:15am
 
What is your source?
If that's a text file, just open it in a good text editor and replace \ with nothing.
If the source is dynamic, you can do link = link.replaceAll("\\\\", "");
Re: Using for() to find characters in text.
Reply #2 - Feb 6th, 2010, 7:55am
 
PhiLho  wrote on Feb 6th, 2010, 7:15am:
link = link.replaceAll("\\\\", "");[/tt]


Does this replace patterns of "\\\\" with empty characters or any occurrence of the '\' character I hadnt spotted replaceAll in the reference..if this regex

Re: Using for() to find characters in text.
Reply #3 - Feb 6th, 2010, 8:16am
 
Quote:
Does this replace patterns of "\\\\" with empty characters or any occurrence of the '\' character

It would replace the "\\" pattern. You need two backslashes to select a backslash, because the backslash is the escape character...

You didn't spot it because it's not in the Processing Reference - but it is in the Java Reference.
Page Index Toggle Pages: 1