Problems with Strings

Results 1 to 2 of 2

Thread: Problems with Strings

  1. #1
    Join Date
    Dec 1969

    Default Problems with Strings

    Hey all,<BR><BR>I have to search through a string for the existance of apostrophe&#039;s and then insert an escape character before these apostrophe&#039;s. I can find the index of the characters fine, just when I try to perform the Insert method, my page freezes. I&#039;m not really sure what I&#039;m doing wrong :-/<BR><BR>Any help would be appriciated :)<BR><BR>Code: <BR>//Insert an escape character if an apostrophe occurs in the title string<BR>for(int start = 0; start &#060;= title.Length -1; start ++)<BR>{<BR> at = title.IndexOf("&#039;", start);<BR> title = title.Insert(at, "\");<BR> <BR> if(at == -1) break;<BR> at = start+1;<BR>}<BR><BR>Cheers,<BR>svyeta

  2. #2
    Join Date
    Dec 1969

    Default Look at the String.replace method

    You don&#039;t need to do any searching or inserting, at all.<BR><BR>Also, both String.Replace and StringBuilder.Replace are defined.<BR><BR>Having said that... Your code is more than a little ugly, even limiting yourself to those two methods.<BR><BR>Better might be:<BR><BR>int start = 0;<BR>int at;<BR>while ( true )<BR>{<BR> at = title.IndexOf("&#039;", start);<BR> if ( at &#060; 0 ) break;<BR> title = title.Inser(at, "\");<BR> start = at+2;<BR>}<BR><BR>But use Replace, instead. TONS faster.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts