Weird StringBuilder problem

Results 1 to 2 of 2

Thread: Weird StringBuilder problem

  1. #1
    Join Date
    Dec 1969

    Default Weird StringBuilder problem

    I am having a problem building a string by iterating through a loop. My code goes through a loop 26 times and concatenates data from a NameValueCollection object to a StringBuilder object. My problem is that when it reaches almost the end of the 7th iteration of the loop, it stops concatenating the string. I have verified that there is data in the NVCollection. Another weird thing is that when I output the string to the browser, it displays what it is supposed to, but when I step through the debugger or email the string to myself, it cuts off the string after j = 7. Does anyone have any ideas?<BR><BR>Here is my code:<BR><BR>NameValueCollection NVCollection = new NameValueCollection();<BR><BR> NVCollection["key"] = key;<BR> NVCollection["step"] = step;<BR> NVCollection["id"] = id;<BR> NVCollection["action"] = action;<BR> NVCollection["name"] = name;<BR> NVCollection["url"] = url;<BR> NVCollection["ecom_username"] = ecom_username;<BR> NVCollection["ecom_password"] = ecom_password.Trim();<BR> NVCollection["username"] = username;<BR> NVCollection["password1"] = password1.Trim();<BR> NVCollection["password2"] = password2.Trim();<BR> NVCollection["contactname"] = contactname;<BR> NVCollection["address1"] = address1;<BR> NVCollection["city"] = city;<BR> NVCollection["region"] = region;<BR> NVCollection["prov"] = prov;<BR> NVCollection["country"] = country;<BR> NVCollection["postalcode"] = postalcode;<BR> NVCollection["postal"] = postal;<BR> NVCollection["phone"] = phone;<BR> NVCollection["fax"] = fax;<BR> NVCollection["email"] = email;<BR> NVCollection["contact"] = contact;<BR> NVCollection["notes"] = notes;<BR> NVCollection["region_other"] = region_other;<BR> NVCollection["address2"] = address2;<BR><BR><BR>for (int j=0;j&#060;NVCollection.Count;j++)<BR> {<BR> thedata.Append(NVCollection.Keys[j]);<BR> thedata.Append(" = ");<BR> thedata.Append(NVCollection[j].Trim());<BR> //stops appending here when j = 7, but still continues to go through for loop<BR> thedata.Append("[br]");<BR> }

  2. #2

    Default RE: Weird StringBuilder problem

    This works for me, try with the hard coded values.<BR><BR><BR> System.Text.StringBuilder thedata= new System.Text.StringBuilder();<BR> System.Collections.Specialized.NameValueCollection NVCollection = new System.Collections.Specialized.NameValueCollection (); <BR><BR> NVCollection["key"] = "key";<BR> NVCollection["step"] = "step";<BR> NVCollection["id"] = "id";<BR> NVCollection["action"] = "action";<BR> NVCollection["name"] = "name";<BR> NVCollection["url"] = "url";<BR> NVCollection["ecom_username"] = "ecom_username";<BR> NVCollection["ecom_password"] = "ecom_password.Trim()";<BR> NVCollection["username"] = "username";<BR> NVCollection["password1"] = "password1.Trim()";<BR> NVCollection["password2"] = "password2.Trim()";<BR> NVCollection["contactname"] = "contactname";<BR> NVCollection["address1"] = "address1";<BR> NVCollection["city"] = "city";<BR> NVCollection["region"] = "region";<BR> NVCollection["prov"] = "prov";<BR> NVCollection["country"] = "country";<BR> NVCollection["postalcode"] = "postalcode";<BR> NVCollection["postal"] = "postal";<BR> NVCollection["phone"] = "phone";<BR> NVCollection["fax"] = "fax";<BR> NVCollection["email"] = "email";<BR> NVCollection["contact"] = "contact";<BR> NVCollection["notes"] = "notes";<BR> NVCollection["region_other"] = "region_other";<BR> NVCollection["address2"] = "address2";<BR><BR><BR> for (int j=0;j&#060;NVCollection.Count;j++) <BR> { <BR> thedata.Append(NVCollection.Keys[j]); <BR> thedata.Append(" = "); <BR> thedata.Append(NVCollection[j].Trim()); <BR> //stops appending here when j = 7, but still continues to go through for loop <BR> thedata.Append("[br]"); <BR> } <BR> Response.Write(thedata.ToString());

Posting Permissions

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