Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 13th, 2003, 11:55 PM
dubsaru dubsaru is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: the desert
Posts: 6 dubsaru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to dubsaru Send a message via AIM to dubsaru Send a message via Yahoo to dubsaru
Question Need help with character replacement

For any Java programmers out there:

I need a way to cut the ^ characters and the character following the ^ and replace it with the correct HTML syntax.

For example:

Input: ^1=^3SWAT^1=^4DerKammisar
Output: <font face="Arial" size="4" color="#FF0000">=</font><font face="Arial" size="4" color="#FFFF00">SWAT</font><font face="Arial" size="4" color="#FF0000">=</font><font face="Arial" size="4" color="#0000FF">DerKammisar</font>

I've written some code that strips the items but not replaces it:
PHP Code:
 Code

   public static 
String parseStripName(String strLineIn) { 
      
String strOut ""
      
int j 0
      if (
strLineIn.indexOf("^")==-1) { 
         
strOut strLineIn
      } else { 
         for(
int i=0;i<strLineIn.length();i++) { 
            
String strChar strLineIn.substring(i,i+1); 
            if (
strChar.equals("^")) { 
               
i
            } else { 
               if (
i==j+1) { 
                  
//System.out.println("Don't Print:"+ Integer.toString(j)); 
               
} else { 
                  
strOut strOut strChar
               } 
            } 
         } 
      } 
      return 
strOut
   } 



Thanks for the help in advance!

Reply With Quote
  #2  
Old April 14th, 2003, 09:05 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
Personally, I would use regular expressions for this. you could use the String.replaceAll() method
replaceAll

Tutorial

Reply With Quote
  #3  
Old April 14th, 2003, 03:26 PM
dubsaru dubsaru is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: the desert
Posts: 6 dubsaru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to dubsaru Send a message via AIM to dubsaru Send a message via Yahoo to dubsaru
Oi, this is going to take a while... But thanks. I do appreciate it. However I ran into a problem, is there a way I can tell it to only replace the character following the ^ if it is an interger?

Reply With Quote
  #4  
Old April 14th, 2003, 06:13 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
Yes. There really is nothing that comes close to the power of regular expressions for text manipulation. You can be very precise on what you want replaced. you can replace all carats(^) only if they are followed by a digit and leave all other carats intact. If you plan on doing any serious programming in your life you will never regret learning regexs. If you need help when making them, post what you have here and I will help you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Need help with character replacement


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway