3 Replies Latest reply: Apr 4, 2011 12:13 PM by 758606 RSS

    how to devide a string in the particular format

    758606
      hi friends

      my problem is that i have a string line having 150 character. i have to devide that string line by 70+70+10 character in such a way that the last word in the each line should be at single location. e.g

      this is a dummy line of string and the characters in this line are important


      suppose this is first line the 70 characerrs completes at impporant "imp" so is should keep this word together is the word length grater than 5 or 6 character then whole character should come in next line begining.



      so friends please suggest me the logic to implement that. string of line may contain any of words with or without space.

      the string is dynamic.


      thanks in advance.
        • 1. Re: how to devide a string in the particular format
          796440
          First you need to very clearly and precisely describe your problem. You haven't done that so far.

          Something like this:

          1. Each line must be no more than 70 characters long.

          2. If the 70-character limit comes in the middle of a word, the line breaks before that word.

          3. If a word is longer than 70 characters, the line will be be broken mid-word at multiples of 70 characters.

          This is just an example, and it may or may not adequately cover your requirements. The point is that you must clearly and unambiguously cover every possible case, and there must be no internal contradictions.

          Edited by: jverd on Apr 4, 2011 10:07 AM
          • 2. Re: how to devide a string in the particular format
            758606
            i have a string having 150 character i want to devide that string in three line first lien may contain 70 character second line also caontain 70 char and third line may contain 10 characters. but at the last word of the line should not be devided. if the last word length is 5 of 6 than the first line may have 75 or 76 character id the last word length is higher than 5 or 6 than the last word should be at initial word of second line and the forst line may have some less characters and so on for second and third line.

            for example

            suppose this is the some exaple of line is contains 77 characters

            "this is a dummy line of strings and the characters in this line are important"

            the 70 character complete in ""this is a dummy line of strings and the characters in this line are im"
            but the last word is devided in two parts it should not be there. if length of the last char is 5 or 6 beyond 70 char then the word should be in the first line

            so frirst line should be
            "this is a dummy line of strings and the characters in this line are" and "important" word should come at second line.
            • 3. Re: how to devide a string in the particular format
              796440
              user9950484 wrote:
              i have a string having 150 character
              Is it always exactly 150 characters? Or is 150 just an example?
              i want to devide that string in three line
              Will you always be dividing your input strings into 3 lines? Or is it just that your rules work out to 3 lines for a 150-char input?
              first lien may contain 70 character
              It "may"? Does that mean that is also might not contain 70? If it's not always 70, why not?

              I'm not reading any more. This is still too vague.