string method

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

    #1

    string method

    How do you detect a string's right 3 charaters, say
    string "abcde". I'd like to detect if the right three
    charaters are "cde", then proceeding doing something.
    Anyone know which method shall I use? Thanx.
  • sridhar

    #2
    RE:string method

    Using VB.NET
    ---------------
    Dim myString As String = "Hello World!"
    Dim subString As String
    subString = Microsoft.Visua lBasic.Right(my String, 6) '
    Returns "World!"


    [color=blue]
    >-----Original Message-----
    >How do you detect a string's right 3 charaters, say
    >string "abcde". I'd like to detect if the right three
    >charaters are "cde", then proceeding doing something.
    >Anyone know which method shall I use? Thanx.
    >.
    >[/color]

    Comment

    • Keith Patrick

      #3
      Re: string method

      Since we're talking .Net here, try String.EndsWith (string)


      "July" <baobei1627@aol .com> wrote in message
      news:077801c35b af$af83ca00$a10 1280a@phx.gbl.. .[color=blue]
      > How do you detect a string's right 3 charaters, say
      > string "abcde". I'd like to detect if the right three
      > charaters are "cde", then proceeding doing something.
      > Anyone know which method shall I use? Thanx.[/color]


      Comment

      • SR

        #4
        RE:string method

        Hi

        Given the fact that
        a) VB.Net is completel;y objectoriented
        b) Microsoft.Visua lbasic namespace is given for backward
        compatibility

        suggest that u use the String Object props/methods like
        length, substring instead of Functions like Right()

        The following code sniper will do wat u want.
        Watch for Line wraps

        Right("abcde", 3) ' Will Return "cde"

        Sub Right(ByVal p_strData As String, ByVal
        p_intNoOfCharsT oGet As Integer)
        If Not p_strData Is Nothing AndAlso
        p_strData.Lengt h >= p_intNoOfCharsT oGet Then
        Console.WriteLi ne(p_strData.Su bstring
        ((p_strData.Len gth - p_intNoOfCharsT oGet),
        p_intNoOfCharsT oGet))
        End If
        End Sub

        regards,

        sr

        [color=blue]
        >-----Original Message-----
        >Using VB.NET
        >---------------
        >Dim myString As String = "Hello World!"
        >Dim subString As String
        >subString = Microsoft.Visua lBasic.Right(my String, 6) '
        >Returns "World!"
        >
        >
        >[color=green]
        >>-----Original Message-----
        >>How do you detect a string's right 3 charaters, say
        >>string "abcde". I'd like to detect if the right three
        >>charaters are "cde", then proceeding doing something.
        >>Anyone know which method shall I use? Thanx.
        >>.
        >>[/color]
        >.
        >[/color]

        Comment

        • Jon Skeet

          #5
          Re: string method

          Keith Patrick <richard_keith_ patrick@nospam. hotmail.com> wrote:[color=blue]
          > Since we're talking .Net here, try String.EndsWith (string)[/color]

          Doh! That'll teach me to not bother looking at the MSDN to see whether
          there's a better way than using primitive tools such as Length, IndexOf
          and Substring :)

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          • gt

            #6
            Re: string method

            try regular expressions
            they can find just about anything and return the "other"
            stuff as well
            lots of examples

            [color=blue]
            >-----Original Message-----
            >July <baobei1627@aol .com> wrote:[color=green]
            >> How do you detect a string's right 3 charaters, say
            >> string "abcde". I'd like to detect if the right three
            >> charaters are "cde", then proceeding doing something.
            >> Anyone know which method shall I use? Thanx.[/color]
            >
            >Use a combination of Substring and Length to get the[/color]
            right 3[color=blue]
            >characters, or (slightly more efficiently) use IndexOf[/color]
            and specify the[color=blue]
            >position to start looking as three characters from the[/color]
            end of the[color=blue]
            >string.
            >
            >--
            >Jon Skeet - <skeet@pobox.co m>
            >http://www.pobox.com/~skeet/
            >If replying to the group, please do not mail me too
            >.
            >[/color]

            Comment

            Working...