Web Analytics Made Easy -
StatCounter Looping through string varible - CodingForum

Announcement

Collapse
No announcement yet.

Looping through string varible

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Looping through string varible

    Hi all..
    I'm making a custom HTMLarea for myself, i'm using special tags i made to modify text formating, like the size and color,......., Just like this forums HTMLarea
    Here's what i reached at last
    Code:
    private string ModifyBody(string Body)
        {
            char[] charBody = Body.ToCharArray();
            StringBuilder sb = new StringBuilder();
            string strBody = "", modBody = "";
            string rtg, ltg;
    
            for (int i = 0; i < charBody.Length; i++)
            {
                sb.Append(charBody[i].ToString());
                strBody = sb.ToString();
    
                //modify size
                if (strBody.IndexOf("[size=") != -1 && strBody.IndexOf("[/size]") != -1)
                {
                    rtg = "[size=";
                    ltg = "[/size]";
                    int start = strBody.IndexOf(rtg);//0;
                    int end = (strBody.IndexOf(ltg) + ltg.Length);//(i + 1);
    
                    // cut the tags and text in tags and put them in other string
                    modBody = strBody.Substring(start, end);
    
                    // modify the tags and replace them with html tags
                    modBody = modBody.Replace("[size=", "<font size=");
                    modBody = modBody.Replace("[/size", "</font");
                    modBody = modBody.Replace("]", ">");
    
                    // place the new modified string in the sb variable
                    sb.Replace(strBody.Substring(start, end), modBody);
    
                    strBody = sb.ToString();
                    //break;
                }
            }
    
            return strBody;
        }
    and here's the variable value that i'm trying to modify
    Code:
    just new function
    all new body function
    [color= #A0522D]Color Text[/color]
    the one body function
    not that i intended to leave this blank space so this forum wont parse it
    and here's the error i get when i execute the code

    Index and length must refer to a location within the string.
    Parameter name: length
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
    Parameter name: length

    Source Error:

    Line 70:
    Line 71: // cut the tags and text in tags and put them in other string
    Line 72: modBody = strBody.Substring(start, end);
    Line 73:
    Line 74: // modify the tags and replace them with html tags


    when i try to use break keyword, it works pretty fine with the first line.
    also check out this image that i took while trying to debug it, it will show that the string variable is correct and going fine.
    Thank you for your help.

    http://www11.brinkster.com/cipherk/stringLoop.JPG
    i need a creative atmosphere
Working...
X