Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 14th, 2003, 10:26 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
Java: addSlashes() ?

I've searched all over for an addSlashes() method...
does anyone know if such a thing exists?

i'm thinking of something along the lines of PHP's addSlashes, where it'll put a \ before every ', ideally for use before executing commands on a database...

Reply With Quote
  #2  
Old October 15th, 2003, 07:17 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to dhouston
I think you'll probably have to roll your own.

Reply With Quote
  #3  
Old October 15th, 2003, 07:59 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
heh, guess i'm just used to being lazy...
I had found one package, although all it did was replace the single quotes with slashes...

when i get it done, i'll post the results for others

Reply With Quote
  #4  
Old October 16th, 2003, 10:03 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
I was playing around with the replace() method of the String class, only to be frustrated by the fact that it replaces characters, and not strings... i couldn't do String a = a.replace('a',"ab");

Before attempting to write my own method, i decided to search for one already written... i'm pleased to announce, i found one! =) [ya, i'm lazy]

This code was posted on another forum:

Code:
/* Replace all instances of a String in a String.
 *   @param  s  String to alter.
 *   @param  f  String to look for.
 *   @param  r  String to replace it with, or null to just remove it.
 */  

public String replace( String s, String f, String r )
{
   if (s == null)  return s;
   if (f == null)  return s;
   if (r == null)  r = "";

   int index01 = s.indexOf( f );
   while (index01 != -1)
   {
      s = s.substring(0,index01) + r + s.substring(index01+f.length());
      index01 += r.length();
      index01 = s.indexOf( f, index01 );
   }
   return s;
}


basically use the method like this:
replace(original_string, search_string, replace_with);


thus, for my purposes, i will do:
replace("I'm sure this works","\'","\\\'");



--------
credit is given to "idarke" from the tek-tips.com forums
http://www.tek-tips.com/gviewthread.../269/qid/657910

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Java: addSlashes() ?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap