Removing items from string & adding new line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pieandpeas
    New Member
    • Sep 2007
    • 43

    Removing items from string & adding new line

    I have a string which looks like this - sometext;;somet ext;;sometext;; sometext

    i'd like to have it displaying on a page looking like this

    sometext
    sometext
    sometext
    sometext

    i know i need a loop and a split, but i'm not sure how to get it working, any help would be great, thanks
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Not necessarily. If we assume for the moment that your string is in a variable called YourString and there's a multiline textbox called Text1 on the form, try this...

    [CODE=vb]Text1.Text = Replace(YourStr ing, ";;", vbNewLine)[/CODE]

    Comment

    • jrtox
      New Member
      • Sep 2007
      • 89

      #3
      Originally posted by pieandpeas
      I have a string which looks like this - sometext;;somet ext;;sometext;; sometext

      i'd like to have it displaying on a page looking like this

      sometext
      sometext
      sometext
      sometext

      i know i need a loop and a split, but i'm not sure how to get it working, any help would be great, thanks

      Where did you store your String"sometext ;;sometext;;som etext;;sometext "?

      lets say that your "sometext;;some text;;sometext; ;sometext" is the object Text1.
      then we can do coding as:
      Text1.Text = Replace(Text1.T ext, ";;", vbNewLine)

      Note:
      During Design time set Multiline to TRUE.

      Regards

      Comment

      • pieandpeas
        New Member
        • Sep 2007
        • 43

        #4
        ideally i'd like to have it display in either a label or via response.write

        the solutions that have been posted make the string sometext;;somet ext;;sometext etc.. display as

        sometext sometext sometext - but with no new line breaks, how would i get it to display as
        sometext
        sometext
        sometext etc.

        current code

        > lblmach.Text = Replace(stringm ach, ";;", vbNewLine)

        Comment

        • QVeen72
          Recognized Expert Top Contributor
          • Oct 2006
          • 1445

          #5
          Hi,

          Make Labels's property WordWrap = True and display..

          Label1.Caption = Replace(MyStrin g,";;",vbCrLf )

          REgards
          Veena

          Comment

          • pieandpeas
            New Member
            • Sep 2007
            • 43

            #6
            i'm using vs2005, a label control doesnt seem to have wordwrap.

            Comment

            • creative1
              Contributor
              • Sep 2007
              • 274

              #7
              If you are using Textbox to display results then, the only thing you need to do is set Multiline property then try this code
              Text1.Text = Replace(YourStr ing, ";;", vbNewLine)

              If you are using label then this code will work as it is.

              regards
              farhana

              Comment

              • pieandpeas
                New Member
                • Sep 2007
                • 43

                #8
                output from a label
                sometext sometext sometext

                Comment

                • QVeen72
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1445

                  #9
                  Originally posted by pieandpeas
                  i'm using vs2005, a label control doesnt seem to have wordwrap.
                  Hi,

                  for VB.net 2005, Label Control will display MultiLine by default, u dont have to set any properties...


                  REgards
                  Veena

                  Comment

                  • pieandpeas
                    New Member
                    • Sep 2007
                    • 43

                    #10
                    yes you are right, however the replace line is only removing the commas from the delimited string, it is not adding a new line in between each word. therefore the text will display not as a multiline, but as one string

                    the string is similar to this some text;;text;;mor e text;;even more text;; !

                    Comment

                    • QVeen72
                      Recognized Expert Top Contributor
                      • Oct 2006
                      • 1445

                      #11
                      Originally posted by pieandpeas
                      yes you are right, however the replace line is only removing the commas from the delimited string, it is not adding a new line in between each word. therefore the text will display not as a multiline, but as one string
                      Hi,

                      New Line will be added, only if it finds ";;" ...
                      If it encounters only one semicolon, new line will not be added.
                      You need to check the String again..


                      Regards
                      Veena

                      Comment

                      • pieandpeas
                        New Member
                        • Sep 2007
                        • 43

                        #12
                        before replace line -

                        Leaflets;;Broch ures to 50,000+ colour;;All stationary, including letterheads, business compliment slips;;NCR carbonless options

                        after replace line -

                        Leaflets Brochures to 50,000+ colour All stationary, including letterheads, business compliment slips NCR carbonless options

                        Comment

                        • QVeen72
                          Recognized Expert Top Contributor
                          • Oct 2006
                          • 1445

                          #13
                          Hi,

                          You must be using ASP.net, my code was for VB.net.
                          I don't know why NewLine does not work, anyway here is the workaround:
                          say your string variable is MyString

                          [code=vb]
                          Dim TArr
                          Dim i As Integer
                          TArr = MyString.Split( ";;")
                          For i = 0 To UBound(TArr)
                          Response.Write( TArr(i) & "<br>")
                          Next
                          [/code]

                          Regards
                          Veena

                          Comment

                          • pieandpeas
                            New Member
                            • Sep 2007
                            • 43

                            #14
                            fantastic! thanks alot!

                            Comment

                            Working...