Results 1 to 10 of 10
-
28-06-2012, 11:07 AM #1
[ASP.net][C#] String.TrimEnd() method
Read this after reading the "Edit" section below

Spoiler:
I'm fetching 3 records, and maybe because the div I added last isn't included in 'lb_left_inner', I only get one.
Spoiler:
EDIT:
I decided to use this, and I think this does the job
s = s.Substring(0, s.Length - 6);
still, I can get only 1 division added to the previous content.Twitter: twitter.com/SharmaTushar
Facebook: facebook.com/tushar.sharma
-
28-06-2012, 07:53 PM #2
Re: [ASP.net][C#] String.TrimEnd() method
Hey u have used for loop for TrimEnd
for (int x = 0; x < 5; x++)
s = s.TrimEnd(endDiv);
no need of for loop..remove that & it will work.HTC One V | Nokia 5233 | Nikon D3100 | Apple Ipod Touch 4G | Sound Magic PL21 | Sound Magic ES18
-
29-06-2012, 11:12 AM #3
Re: [ASP.net][C#] String.TrimEnd() method
I figured that because my TrimStart() did work, oddly enough TrimEnd() doesn't. Anyway if 5 iterations didn't make a change to the string, I guess 1 won't.
Driving away from the Topic title, Trimming the end is least of concern for now, which I can do now using substring, not too efficient, but does the job for now; the problem for now is that lb_left_inner.RenderControl returns the same HTML over and over, without any change being reflected, so after the loop, only 1 div is being added.
EDIT:
I misjudged what InnerHtml does, the following code works for me, I didn't need to set InnerHtml of lb_left, lb_left_inner.InnerHtml doesn't indicate what's inside its tags, rather its whole body.
Code:protected void Page_Load(object sender, EventArgs e) { BLL rbll = new BLL(); try { DataTable dt = rbll.SelectAllProperties(); foreach (DataRow dr in dt.Rows) { string[] arr = new string[dt.Columns.Count]; int i = 0; foreach (DataColumn dc in dt.Columns) { arr[i] = dr[dc].ToString(); i++; } System.Text.StringBuilder sb = new System.Text.StringBuilder(); lb_left_inner.RenderControl(new HtmlTextWriter(new System.IO.StringWriter(sb))); string s = sb.ToString(); this.lb_left_inner.InnerHtml = s + "<div class=\"inner-cont\"><img src=\"" + arr[16].TrimStart(new char[] { '~', '/' }) + "\" runat=\"server\"/><h3 class=\"room-type\">Rent a commercial room</h3><p>Jaipur, IX ker<br />105 000 Ft/mo<br />75 m2 / 3 bed / 1 liv / 1 bath</p><a class=\"more\">More Details</a></div>"; } } catch (Exception exc) { Response.Write("<h1>" + exc.Message + "</h1>"); } finally { rbll = null; } }Twitter: twitter.com/SharmaTushar
Facebook: facebook.com/tushar.sharma
-
29-06-2012, 11:18 AM #4
Re: [ASP.net][C#] String.TrimEnd() method
using a for loop u r doing 25 iterations...bcoz u have used a char array of length which has its own pattern match iterations so 5*5 = 25 iterations.
& believe removing the for loop will do the work (tried & tested) instead of a hard-coded value of 6 in substring.HTC One V | Nokia 5233 | Nikon D3100 | Apple Ipod Touch 4G | Sound Magic PL21 | Sound Magic ES18
-
29-06-2012, 11:28 AM #5
Re: [ASP.net][C#] String.TrimEnd() method
I tried it at first, but for some reason didn't work, and doesn't work even now.
Current code has totally eliminated the need of Trimming, but I hope I'll get it right in future if need arises.
Twitter: twitter.com/SharmaTushar
Facebook: facebook.com/tushar.sharma
-
29-06-2012, 07:33 PM #6
Re: [ASP.net][C#] String.TrimEnd() method
^I don't know why it didn't work for u.
I copy/pasted your above code & it was trimming the </div> when for loop is not usedHTC One V | Nokia 5233 | Nikon D3100 | Apple Ipod Touch 4G | Sound Magic PL21 | Sound Magic ES18
-
29-06-2012, 11:41 PM #7
Re: [ASP.net][C#] String.TrimEnd() method
I can vouch for Zangetsu, TrimEnd(charArray) removes trailing occurrences of all characters present in the array. Tried and tested. The reason it might be failing could be because of a stray whitespace. But that's just a wild guess.
AMD Phenom II X6 1055T|MSI 880GMA-E45|MSI 7770|2x2 Corsair DDR3 1333MHz|CM Elite 310|Corsair CX400W|DELL ST2320L
Myself @ nbaztec.co.in
Build Your Rig! (XBlade) @ nbaztec.co.in - Build Your Rig!
My Inner Artist @ nbaztec.co.in - Designs
-
02-07-2012, 11:08 AM #8
Re: [ASP.net][C#] String.TrimEnd() method
^that's what I was explaining to OP
HTC One V | Nokia 5233 | Nikon D3100 | Apple Ipod Touch 4G | Sound Magic PL21 | Sound Magic ES18
-
02-07-2012, 01:44 PM #9
Re: [ASP.net][C#] String.TrimEnd() method
Twitter: twitter.com/SharmaTushar
Facebook: facebook.com/tushar.sharma
-
02-07-2012, 08:39 PM #10
Re: [ASP.net][C#] String.TrimEnd() method
Well there can be many reasons for that, but a tried & tested library function failing, would be my - and I can not emphasize this enough - very last guess.
The TrimEnd() would remove only the first occurrence of '</div>' after that the spaces would cause it to return. I'm still guessing a stray space, \t or a CR/LF at the end is messing it up.AMD Phenom II X6 1055T|MSI 880GMA-E45|MSI 7770|2x2 Corsair DDR3 1333MHz|CM Elite 310|Corsair CX400W|DELL ST2320L
Myself @ nbaztec.co.in
Build Your Rig! (XBlade) @ nbaztec.co.in - Build Your Rig!
My Inner Artist @ nbaztec.co.in - Designs
Similar Threads
-
Need help with vb connection string
By arian29 in forum ProgrammingReplies: 9Last Post: 02-09-2008, 01:55 PM -
String.replace
By estranged12 in forum ProgrammingReplies: 2Last Post: 09-04-2008, 09:58 AM -
C++ String to all conversion.... Help needed...
By aditya.shevade in forum ProgrammingReplies: 8Last Post: 06-03-2008, 11:33 PM -
cant declare a string variable...
By geekgod in forum Open SourceReplies: 13Last Post: 12-08-2006, 06:09 AM -
asp 'replace' string query!
By 144 in forum QnA (read only)Replies: 1Last Post: 30-06-2006, 10:35 AM


LinkBack URL
About LinkBacks

Reply With Quote

Bookmarks