Visual Basic 2008 - Trim ?

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

    Visual Basic 2008 - Trim ?

    Hey all,

    I need to trim the first couple of letters from a string and stop a
    particular character.

    Here is some code for example:

    DN = "CN=username,OU =computers,OU=a bingdon, OU=MAR,
    OU=Customers,DC =company,DC=com "

    I need to get rid of just the "CN=usernam e," part (note that i need to
    get rid of the " , " also)

    I ran across an article that talks about trim() but dont know how that
    would work since the usernames will be different every time.

    help ?
  • zacks@construction-imaging.com

    #2
    Re: Visual Basic 2008 - Trim ?

    On Oct 3, 1:03 pm, brett <planetbr...@gm ail.comwrote:
    Hey all,
    >
    I need to trim the first couple of letters from a string and stop a
    particular character.
    >
    Here is some code for example:
    >
    DN = "CN=username,OU =computers,OU=a bingdon, OU=MAR,
    OU=Customers,DC =company,DC=com "
    >
    I need to get rid of just the "CN=usernam e," part (note that i need to
    get rid of the " , " also)
    >
    I ran across an article that talks about trim() but dont know how that
    would work since the usernames will be different every time.
    >
    help ?
    Assuming VB.NET:

    DB = DB.Replace("CN= username,", "")

    Comment

    • =?ISO-8859-1?Q?G=F6ran_Andersson?=

      #3
      Re: Visual Basic 2008 - Trim ?

      brett wrote:
      Hey all,
      >
      I need to trim the first couple of letters from a string and stop a
      particular character.
      >
      Here is some code for example:
      >
      DN = "CN=username,OU =computers,OU=a bingdon, OU=MAR,
      OU=Customers,DC =company,DC=com "
      >
      I need to get rid of just the "CN=usernam e," part (note that i need to
      get rid of the " , " also)
      >
      I ran across an article that talks about trim() but dont know how that
      would work since the usernames will be different every time.
      >
      help ?
      The trim method is used to trim off specific characters, for example
      trimming off leading and trailing spaces.

      Use the IndexOf method to get the location of the first comma, then use
      the Substring method to get the part of the string after the comma.

      --
      Göran Andersson
      _____
      Göran Anderssons privata hemsida.

      Comment

      • Tom Shelton

        #4
        Re: Visual Basic 2008 - Trim ?

        On 2008-10-03, brett <planetbrett@gm ail.comwrote:
        Hey all,
        >
        I need to trim the first couple of letters from a string and stop a
        particular character.
        >
        Here is some code for example:
        >
        DN = "CN=username,OU =computers,OU=a bingdon, OU=MAR,
        OU=Customers,DC =company,DC=com "
        >
        I need to get rid of just the "CN=usernam e," part (note that i need to
        get rid of the " , " also)
        >
        I ran across an article that talks about trim() but dont know how that
        would work since the usernames will be different every time.
        >
        help ?
        hmmm off the top, something like:

        Dim original = "CN=username,OU =computers,OU=a bingdon, OU=MAR,OU=Custo mers,DC=company ,DC=com"
        Dim parts() As String = original.Split( ",".ToCharArray ())
        Dim newString = String.Join("," , parts, 1, parts.Length - 1)
        Console.WriteLi ne(newString)

        Or

        Dim original As String = "CN=username,OU =computers,OU=a bingdon, OU=MAR,OU=Custo mers,DC=company ,DC=com"
        Dim s As String = original.Substr ing(original.In dexOf(","c) + 1)
        Console.WriteLi ne(s)

        HTH
        --
        Tom Shelton

        Comment

        • James Hahn

          #5
          Re: Visual Basic 2008 - Trim ?

          Use indexof to find the position of the first quotation mark, and indexof to
          find the first comma, then two substring operations to get the part up and
          including the quote and everything after the comma.

          (I'm assuming username will be different each time)

          A regular expression would be the proper way to do it.

          "brett" <planetbrett@gm ail.comwrote in message
          news:d96628e3-8e28-4ec5-bea5-ff44dee7fa8f@m3 g2000hsc.google groups.com...
          Hey all,
          >
          I need to trim the first couple of letters from a string and stop a
          particular character.
          >
          Here is some code for example:
          >
          DN = "CN=username,OU =computers,OU=a bingdon, OU=MAR,
          OU=Customers,DC =company,DC=com "
          >
          I need to get rid of just the "CN=usernam e," part (note that i need to
          get rid of the " , " also)
          >
          I ran across an article that talks about trim() but dont know how that
          would work since the usernames will be different every time.
          >
          help ?

          Comment

          • brett

            #6
            Re: Visual Basic 2008 - Trim ?

            Thanks Tom!
            I ended up incorporating something like your first example into my
            program.
            Do you know of any good books that i could pickup to help me out with
            VB.NET?

            Thanks to everyone who replied!

            On Oct 3, 4:33 pm, Tom Shelton <tom_shel...@co mcastXXXXXXX.ne twrote:
            On 2008-10-03, brett <planetbr...@gm ail.comwrote:
            >
            >
            >
            Hey all,
            >
            I need to trim the first couple of letters from a string and stop a
            particular character.
            >
            Here is some code for example:
            >
            DN = "CN=username,OU =computers,OU=a bingdon, OU=MAR,
            OU=Customers,DC =company,DC=com "
            >
            I need to get rid of just the "CN=usernam e," part (note that i need to
            get rid of the " , " also)
            >
            I ran across an article that talks about trim() but dont know how that
            would work since the usernames will be different every time.
            >
            help ?
            >
            hmmm off the top, something like:
            >
            Dim original = "CN=username,OU =computers,OU=a bingdon, OU=MAR,OU=Custo mers,DC=company ,DC=com"
            Dim parts() As String = original.Split( ",".ToCharArray ())
            Dim newString = String.Join("," , parts, 1, parts.Length - 1)
            Console.WriteLi ne(newString)
            >
            Or
            >
            Dim original As String = "CN=username,OU =computers,OU=a bingdon, OU=MAR,OU=Custo mers,DC=company ,DC=com"
            Dim s As String = original.Substr ing(original.In dexOf(","c) + 1)
            Console.WriteLi ne(s)
            >
            HTH
            --
            Tom Shelton

            Comment

            Working...