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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Display first (n) number of words of string......

Display first (n) number of words of string......

Scheduled Pinned Locked Moved ASP.NET
lounge
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.
  • M Offline
    M Offline
    munklefish
    wrote on last edited by
    #1

    Hi, I have a string of text of random length but need to display only the first 250 characters (preferably whole words), in a label. Any remaining words would be displayed in a seperate label. Please can someone give me advice on what i need to do or at least the methodology i need to look into. Many Thanks!

    S G 2 Replies Last reply
    0
    • M munklefish

      Hi, I have a string of text of random length but need to display only the first 250 characters (preferably whole words), in a label. Any remaining words would be displayed in a seperate label. Please can someone give me advice on what i need to do or at least the methodology i need to look into. Many Thanks!

      S Offline
      S Offline
      sulabh2020
      wrote on last edited by
      #2

      hey dear it is basics of strings. try to use substring function of string e.g: string strtext; printf(strtext.substring(0,250)); this give u a result.

      Hello Forum Always be in touch to help about the topic ASP.NET

      M 1 Reply Last reply
      0
      • S sulabh2020

        hey dear it is basics of strings. try to use substring function of string e.g: string strtext; printf(strtext.substring(0,250)); this give u a result.

        Hello Forum Always be in touch to help about the topic ASP.NET

        M Offline
        M Offline
        munklefish
        wrote on last edited by
        #3

        Thanks! I knew it was basic, but havent used it for soo long! I was having one of those times when trying to remember just made it harder to think clearly. ;-) Thanks for the reply!!!!

        1 Reply Last reply
        0
        • M munklefish

          Hi, I have a string of text of random length but need to display only the first 250 characters (preferably whole words), in a label. Any remaining words would be displayed in a seperate label. Please can someone give me advice on what i need to do or at least the methodology i need to look into. Many Thanks!

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Use str.LastIndexOf(' ', 250) to find the space closest to the 250th character. If it finds one reasonably close to 250, use str.Substring to get the part of the string up to the space. Otherwise you just have to cut the string at 250 anyway.

          Experience is the sum of all the mistakes you have done.

          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