string question

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

    #1

    string question

    I have gone over allot of the samples and documentation on the internet on
    strings. I am not seeing a good example of a function or sub to remove all
    characters to right or left of a given character. The ones I see I don't
    know how to implement.

    I want to take the following

    c:\temp\otherTe mp
    c:\temp\2ndTemp

    and just returns from what follow after the last"\"

    otherTemp
    2ndTemp

    I see the String.TrimStar t Method...but i cant figure out how to implement
    it.

    thanks


  • Kelly Ethridge

    #2
    Re: string question

    Have you tried Path.GetFileNam e?


    shane wrote:
    I have gone over allot of the samples and documentation on the internet on
    strings. I am not seeing a good example of a function or sub to remove all
    characters to right or left of a given character. The ones I see I don't
    know how to implement.
    >
    I want to take the following
    >
    c:\temp\otherTe mp
    c:\temp\2ndTemp
    >
    and just returns from what follow after the last"\"
    >
    otherTemp
    2ndTemp
    >
    I see the String.TrimStar t Method...but i cant figure out how to implement
    it.
    >
    thanks
    >
    >

    Comment

    • Meelis Lilbok

      #3
      Re: string question


      Hi

      Dim sPath As String = "c:\temp\otherT emp"
      Dim sResult=sPath.S ubstring(sPath. LastIndexOf("\" ) + 1)

      Mex


      "shane" <azcpu@hotmail. comwrote in message
      news:uwAiyl0oHH A.4196@TK2MSFTN GP06.phx.gbl...
      >I have gone over allot of the samples and documentation on the internet on
      >strings. I am not seeing a good example of a function or sub to remove all
      >characters to right or left of a given character. The ones I see I don't
      >know how to implement.
      >
      I want to take the following
      >
      c:\temp\otherTe mp
      c:\temp\2ndTemp
      >
      and just returns from what follow after the last"\"
      >
      otherTemp
      2ndTemp
      >
      I see the String.TrimStar t Method...but i cant figure out how to implement
      it.
      >
      thanks
      >

      Comment

      • Phill W.

        #4
        Re: string question

        shane wrote:
        I want to take the following
        c:\temp\otherTe mp
        c:\temp\2ndTemp
        and just returns from what follow after the last"\"
        Since you're working with file system Paths, how about using the Path
        class in System.IO?

        Imports System.IO

        ? Path.GetFilenam e( "c:\temp\otherT emp" )

        Or, if you're determined to do it the String way ...

        Dim s as String = "c:\temp\otherT emp"
        ? s.SubString( s.LastIndexof( "\" ) + 1 )

        .... but don't be surprised if you get odd results from this, from time
        to time. The methods in Path are far more tolerant of dodgy-looking
        paths.

        HTH,
        Phill W.

        Comment

        • Hal Rosser

          #5
          Re: string question


          "shane" <azcpu@hotmail. comwrote in message
          news:uwAiyl0oHH A.4196@TK2MSFTN GP06.phx.gbl...
          >I have gone over allot of the samples and documentation on the internet on
          >strings. I am not seeing a good example of a function or sub to remove all
          >characters to right or left of a given character. The ones I see I don't
          >know how to implement.
          >
          I want to take the following
          >
          c:\temp\otherTe mp
          c:\temp\2ndTemp
          >
          and just returns from what follow after the last"\"
          >
          otherTemp
          2ndTemp
          >
          I see the String.TrimStar t Method...but i cant figure out how to implement
          it.
          >
          thanks
          >
          Since you asked for a String solution..
          broken down into steps:
          Dim s as String = "c:\temp\otherT emp"
          Dim pos as Integer = s.lastIndexOf(" \") + 1
          Dim strFileName as String = s.substring(pos )

          You may combine a couple of steps
          HTH


          Comment

          • shane

            #6
            Re: string question

            thanks a million guys..That worked great, but I will look at your other
            suggestions . :)
            "Hal Rosser" <hmrosser@bells outh.netwrote in message
            news:JGN7i.1993 4$KC4.2065@bign ews6.bellsouth. net...
            >
            "shane" <azcpu@hotmail. comwrote in message
            news:uwAiyl0oHH A.4196@TK2MSFTN GP06.phx.gbl...
            >>I have gone over allot of the samples and documentation on the internet on
            >>strings. I am not seeing a good example of a function or sub to remove all
            >>characters to right or left of a given character. The ones I see I don't
            >>know how to implement.
            >>
            >I want to take the following
            >>
            >c:\temp\otherT emp
            >c:\temp\2ndTem p
            >>
            >and just returns from what follow after the last"\"
            >>
            >otherTemp
            >2ndTemp
            >>
            >I see the String.TrimStar t Method...but i cant figure out how to
            >implement it.
            >>
            >thanks
            >>
            Since you asked for a String solution..
            broken down into steps:
            Dim s as String = "c:\temp\otherT emp"
            Dim pos as Integer = s.lastIndexOf(" \") + 1
            Dim strFileName as String = s.substring(pos )
            >
            You may combine a couple of steps
            HTH
            >
            >

            Comment

            Working...