Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Cut String !

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Resolved [RESOLVED] [2005] Cut String !

    Hello ,

    I have to cut a String
    the substring method its good but it pass an index as integer
    i have an example like this
    visual | basic

    how can i get f
    First String :visual (from first to | )
    second String :basic (from | to last )

    Thanks !

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2005] Cut String !

    First = MyString.Substring(0, MyString.IndexOf("|")
    Second = MyString.Substring(MyString.IndexOf("|"), MyString.Length - 1)

    http://msdn.microsoft.com/en-us/libr...rs(VS.80).aspx
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: [2005] Cut String !

    Thanks m8

    The first one Working but i got an exception on Second one

    i dont know why ??

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Cut String !

    Use the first method (string.split) and this function returns a string array. You just read the appropriate element in the array to pull out what you need.
    Code:
    Dim parts as string() = mystring.split("|"c)
    If parts.Length > 1 Then
       first = parts(0)
       second = parts(1)
    End If

  5. #5
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2005] Cut String !

    Quote Originally Posted by killer7k
    Thanks m8

    The first one Working but i got an exception on Second one

    i dont know why ??
    Well the errors are very explanatory in .Net. The error should tell you what's wrong then you can look at the documentation I sent you which will show you the way...

    I'll give you a hint. The second parameter of the Substring method is the length of characters to grab. In my example I'm passing how long the entire string is. So a little math jiggering will get you fixed.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: [2005] Cut String !

    Quote Originally Posted by kasracer
    Well the errors are very explanatory in .Net. The error should tell you what's wrong then you can look at the documentation I sent you which will show you the way...

    I'll give you a hint. The second parameter of the Substring method is the length of characters to grab. In my example I'm passing how long the entire string is. So a little math jiggering will get you fixed.

    i cant find an explanation for it at last if i am not adding - 1
    i cant explan it it's length problem use it a lot havent had this problem before

    try it & you will see !


    @stanav


    Thanks m8 Working !

  7. #7
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] [2005] Cut String !

    hey killer what are you trying to do? Are you trying to remove the | or are you trying to make seperate strings of visual | basic? If the latter see Stanav post.

    Both

    Code:
            Dim testString As String = "Visual | Basic | is | easy"
            Dim foo() As String = testString.Split("|"c)
            Debug.WriteLine("'Debug Output")
            For x As Integer = 0 To foo.Length - 1
                Debug.WriteLine("'" & foo(x))
            Next
            testString = testString.Replace("|", "")
            Debug.WriteLine("'" & testString)
            Stop
            'Debug Output
            'Visual 
            ' Basic 
            ' is 
            ' easy
            'Visual  Basic  is  easy
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: [RESOLVED] [2005] Cut String !

    Quote Originally Posted by dbasnett
    hey killer what are you trying to do? Are you trying to remove the | or are you trying to make seperate strings of visual | basic? If the latter see Stanav post.

    Both

    Code:
            Dim testString As String = "Visual | Basic | is | easy"
            Dim foo() As String = testString.Split("|"c)
            Debug.WriteLine("'Debug Output")
            For x As Integer = 0 To foo.Length - 1
                Debug.WriteLine("'" & foo(x))
            Next
            testString = testString.Replace("|", "")
            Debug.WriteLine("'" & testString)
            Stop
            'Debug Output
            'Visual 
            ' Basic 
            ' is 
            ' easy
            'Visual  Basic  is  easy

    I was making it separate

    Code:
    dom strs as String =Textbox1.text
    dim s as String =strs.split("|")
    dim s1,s2 as String 
    
    if s.length > 1 then 
    s1=s(0)
    s2=s(1).TrimStart(" ")
    end if
    Working as Stanav Post

    Thanks !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width