#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    the desert
    Posts
    6
    Rep Power
    0

    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!
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Personally, I would use regular expressions for this. you could use the String.replaceAll() method
    replaceAll

    Tutorial
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    the desert
    Posts
    6
    Rep Power
    0
    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?
  6. #4
  7. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    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.

IMN logo majestic logo threadwatch logo seochat tools logo