none
Searching System RRS feed

  • Question

  • Can I search for the word "VisualBasic" with only a letter 'V' by using the VB language?
    Friday, September 28, 2018 3:43 AM

Answers

  • In this case, use String.StartsWith.

    String methods, StartsWith.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ItemList = New List(Of String) From
            {
                "VisualBasic",
                "Basic",
                "JavaScript",
                "Visual-Basic"
            }
    
        Dim results = ItemList.
            Select(Function(item, row) New With {.Value = item, .Index = row}).
            Where(Function(s) s.Value.IndexOf("V", 0, StringComparison.CurrentCultureIgnoreCase) > -1)
    
        For Each value In results
            Console.WriteLine($"{value.Index} - {value.Value}")
        Next
    
        results = ItemList.
            Select(Function(item, row) New With {.Value = item, .Index = row}).
            Where(Function(s) s.Value.StartsWith("V"))
    
        Console.WriteLine()
    
        For Each value In results
            Console.WriteLine($"{value.Index} - {value.Value}")
        Next
    
        Console.WriteLine()
    
        Dim test = "VisualBasic"
        If test.StartsWith("V") Then
            Console.WriteLine("Yes")
        Else
            Console.WriteLine("Nes")
        End If
    
    End Sub

    Result

    0 - VisualBasic
    2 - JavaScript
    3 - Visual-Basic
    
    0 - VisualBasic
    3 - Visual-Basic
    Yes


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Friday, September 28, 2018 8:56 AM
    Moderator

All replies

  • In this case, use String.StartsWith.

    String methods, StartsWith.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ItemList = New List(Of String) From
            {
                "VisualBasic",
                "Basic",
                "JavaScript",
                "Visual-Basic"
            }
    
        Dim results = ItemList.
            Select(Function(item, row) New With {.Value = item, .Index = row}).
            Where(Function(s) s.Value.IndexOf("V", 0, StringComparison.CurrentCultureIgnoreCase) > -1)
    
        For Each value In results
            Console.WriteLine($"{value.Index} - {value.Value}")
        Next
    
        results = ItemList.
            Select(Function(item, row) New With {.Value = item, .Index = row}).
            Where(Function(s) s.Value.StartsWith("V"))
    
        Console.WriteLine()
    
        For Each value In results
            Console.WriteLine($"{value.Index} - {value.Value}")
        Next
    
        Console.WriteLine()
    
        Dim test = "VisualBasic"
        If test.StartsWith("V") Then
            Console.WriteLine("Yes")
        Else
            Console.WriteLine("Nes")
        End If
    
    End Sub

    Result

    0 - VisualBasic
    2 - JavaScript
    3 - Visual-Basic
    
    0 - VisualBasic
    3 - Visual-Basic
    Yes


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Friday, September 28, 2018 8:56 AM
    Moderator
  • IN which context are you referring? Your question is extremely vague. As it stand the best answer is "Yes"

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Friday, September 28, 2018 1:24 PM
  • Can I search for the word "VisualBasic" with only a letter 'V' by using the VB language?

    In your Subject "Searching System", does this mean:

    "Searching the System" 
    (e.g. - for a file or directory name beginning with V)

    or

    "A System of Searching"
    (e.g. - What systems, methods, algorithms, or tools are available?)

    - Wayne

    Friday, September 28, 2018 4:34 PM