none
How to format a string in vb.net? RRS feed

  • Question

  • hi all.

    I have a string like below:

    dim a as string = "5885 \ STYLE 1 \ BLACK"

    and my requiremnt is that i want to break this string in the following format

    strColor = "BLACK"

    strStyle = "STYLE 1"

    how can i achieve the required format? by vb.net string functions

    Thanks

    Friday, December 28, 2012 12:03 PM

Answers

  • Muhammad kashan khan

    Does this help ?

      Sub Main()
    
          dim a as string = "5885 \ STYLE 1 \ BLACK"
            Dim strColor As String = String.Empty
            Dim strStyle As String = String.Empty
    
    
    
            Dim parts As String() = a.Split("\")
    
            If parts.Length > 2 Then
                strColor = parts(2).Trim
                strStyle = parts(1).Trim
    
    
            End If
            Console.WriteLine("{0} {1}", strColor, strStyle)
    
             
        End Sub

    Friday, December 28, 2012 12:48 PM
  • Try the following

    Dim a As String = "5885 \ STYLE 1 \ BLACK"
    Dim Parts = a.Split("\"c)
    Dim strColor As String = Parts(2).Trim
    Dim strStyle As String = Parts(1).Trim
    MessageBox.Show(String.Format("Style: {0} Color: {1}", strStyle, strColor))


    KSG

    Friday, December 28, 2012 12:52 PM
    Moderator

All replies