Help with strings.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • garth

    #1

    Help with strings.

    Sample data.

    "<td class=small bgcolor="E7E7E7 ">
    Garth Was Here"

    "<br><td class=small bgcolor="13B9C1 ">2006/03/08"



    I'm looking for a two things.



    1) A function to remove whitespaces. In the example data above not
    only are there " " but there could be tabs and carriage returns.

    2) I am also looking to strip off anything before the last ">" within
    the string. I created a function that will do this for me, however for what
    ever reason the InStrRev always returns 0. What I'm I doing wrong or how can
    I fix this?



    Public Function Clean_str(ByVal Str_in As String) As String

    Dim Search As String

    Dim Temp As String

    Dim Temp2 As String

    Dim start As Integer

    Dim L As Integer



    Search = "</td>"

    L = Len(Search)

    start = InStr(Str_in, Search, CompareMethod.T ext)

    Temp2 = Mid(Str_in, 1, start - 1)

    Temp = Mid(Str_in, start + L)



    'Find "> which is before the Date"

    Search = "<br>"

    start = InStr(Temp2, Search, CompareMethod.T ext)

    Temp2 = Mid(Temp2, 1, start - 1)



    Search = ">"

    start = InStrRev(Temp2, Search, CompareMethod.T ext)

    L = Len(Search)

    Temp2 = Mid(Temp2, start + L)

    Temp2 = Trim(Temp2)

    Return Temp2

    End Function


  • zacks@construction-imaging.com

    #2
    Re: Help with strings.

    Are you using VB6? If so, you are posting in the wrong newsgroup. If
    you are using VB.NET, you should look into the String class and all of
    the properties and method available for manipulating string values.

    Comment

    • garth

      #3
      Re: Help with strings.

      I'm using "Microsoft Visual Basic 2005 Express Edition" I have read the Help
      file included but there does not seem to be a reason why the InStrRev always
      returns 0. Also there does not seem to be a Whitespace function.



      Personally I find that the help file is less than helpful, I much prefer the
      help file that SQL server 2000 has to find out more about function and how
      they work.



      <zacks@construc tion-imaging.com> wrote in message
      news:1141824954 .279699.215770@ u72g2000cwu.goo glegroups.com.. .[color=blue]
      > Are you using VB6? If so, you are posting in the wrong newsgroup. If
      > you are using VB.NET, you should look into the String class and all of
      > the properties and method available for manipulating string values.
      >[/color]


      Comment

      • zacks@construction-imaging.com

        #4
        Re: Help with strings.

        Sound like you have yet to grasp the concepts of OOP.

        The InStrRev always returning 0 probably means you have your previous
        Mid function coded incorrectly. Try to dump the value of Temp2 before
        the InStrRev call to make sure.

        You really need to start using the String class methods to manipulate
        strings, the functions you are using are merely provided for backwards
        compatiblilty with VB6.

        For removing things like whitespace, most people use the String.Replace
        method.

        Comment

        • garth

          #5
          Re: Help with strings.

          You are right about the oop. Many moons ago when the grass was green I
          programmed in C and Turbo Pascal since then I have done mostly scripting.
          And I love my command prompt and winfile.exe too! <Grin>

          I did find the Object.trim which does exactly what I want it to do. Also I
          think that I have over come my huddles for now and the function work fine.
          :-)

          Thanks for pointing me in the right direction.

          <zacks@construc tion-imaging.com> wrote in message
          news:1141835294 .828390.257940@ p10g2000cwp.goo glegroups.com.. .[color=blue]
          > Sound like you have yet to grasp the concepts of OOP.
          >
          > The InStrRev always returning 0 probably means you have your previous
          > Mid function coded incorrectly. Try to dump the value of Temp2 before
          > the InStrRev call to make sure.
          >
          > You really need to start using the String class methods to manipulate
          > strings, the functions you are using are merely provided for backwards
          > compatiblilty with VB6.
          >
          > For removing things like whitespace, most people use the String.Replace
          > method.
          >[/color]


          Comment

          Working...