Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Insert <br> for every 10 characters of asp label in C#.net</br> [modified]

Insert <br> for every 10 characters of asp label in C#.net</br> [modified]

Scheduled Pinned Locked Moved ASP.NET
csharphelpdatabasewpfwcf
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    getaccessyr
    wrote on last edited by
    #1

    Hi All, I need to add "
    " i.e. break for every 10characters of text in label which we are binding data from Database.so that the after every 10th character remaining characters will come in next line. i wrote a code but if we have to enter characters as multiples of 10 else it gives error my code is: public static string WrappableText(string source) { //string nwln = Environment.NewLine; //return source.Replace(nwln, "<br />"); ArrayList StringList = new ArrayList(); int a=0; for (int i = 1; i <= 10; i++) { StringList.Add(source.Substring(a, 10)); a += 10; } System.Text.StringBuilder newstring = new System.Text.StringBuilder(); while (StringList.Count>0) { newstring.Append(StringList[0].ToString() + "<br>"); StringList.RemoveAt(0); } return newstring.ToString(); } Is it possible to do? Can any one help me? Thanks In Advance yamuna

    modified on Thursday, October 8, 2009 10:46 AM

    C I 2 Replies Last reply
    0
    • G getaccessyr

      Hi All, I need to add "
      " i.e. break for every 10characters of text in label which we are binding data from Database.so that the after every 10th character remaining characters will come in next line. i wrote a code but if we have to enter characters as multiples of 10 else it gives error my code is: public static string WrappableText(string source) { //string nwln = Environment.NewLine; //return source.Replace(nwln, "<br />"); ArrayList StringList = new ArrayList(); int a=0; for (int i = 1; i <= 10; i++) { StringList.Add(source.Substring(a, 10)); a += 10; } System.Text.StringBuilder newstring = new System.Text.StringBuilder(); while (StringList.Count>0) { newstring.Append(StringList[0].ToString() + "<br>"); StringList.RemoveAt(0); } return newstring.ToString(); } Is it possible to do? Can any one help me? Thanks In Advance yamuna

      modified on Thursday, October 8, 2009 10:46 AM

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Well, you should have told us what the error was. This code is terrible.

      yamunarani wrote:

      ArrayList

      Why use an arraylist ? Is this ASP.NET 1.0 ?

      yamunarani wrote:

      StringList.Add(source.Substring(a, 10));

      Here is your problem. You assume there's 10 characters. Of course you'll get an error if there is not. Work out the string length in code instead.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      G 1 Reply Last reply
      0
      • C Christian Graus

        Well, you should have told us what the error was. This code is terrible.

        yamunarani wrote:

        ArrayList

        Why use an arraylist ? Is this ASP.NET 1.0 ?

        yamunarani wrote:

        StringList.Add(source.Substring(a, 10));

        Here is your problem. You assume there's 10 characters. Of course you'll get an error if there is not. Work out the string length in code instead.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        G Offline
        G Offline
        getaccessyr
        wrote on last edited by
        #3

        Hi, I know that the problem is with the code i used StringList.Add(source.Substring(a, 10)); i tried in other way too,but i dint get the required solution it is failing in other way if any one knows the exact solution plz reply me thanks in advance yamuna

        1 Reply Last reply
        0
        • G getaccessyr

          Hi All, I need to add "
          " i.e. break for every 10characters of text in label which we are binding data from Database.so that the after every 10th character remaining characters will come in next line. i wrote a code but if we have to enter characters as multiples of 10 else it gives error my code is: public static string WrappableText(string source) { //string nwln = Environment.NewLine; //return source.Replace(nwln, "<br />"); ArrayList StringList = new ArrayList(); int a=0; for (int i = 1; i <= 10; i++) { StringList.Add(source.Substring(a, 10)); a += 10; } System.Text.StringBuilder newstring = new System.Text.StringBuilder(); while (StringList.Count>0) { newstring.Append(StringList[0].ToString() + "<br>"); StringList.RemoveAt(0); } return newstring.ToString(); } Is it possible to do? Can any one help me? Thanks In Advance yamuna

          modified on Thursday, October 8, 2009 10:46 AM

          I Offline
          I Offline
          Imran Khan Pathan
          wrote on last edited by
          #4

          TRY THIS ONE. public string WrappedString(string Source) { int count = 0; System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (char c in Source) { count++; sb.Append(c); if (count == 10) { count = 0; sb.Append("< br >"); } } return sb.ToString(); }

          please don't forget to vote on the post that helped you.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups