none
StringBuilder RRS feed

  • Question

  • Hi All..

    Can someone show how to create stringbuilder correctly with this code.

    Begin with StringToCcheck string from List item of Form1.ResultSecondLine.It error before debug.

    Error 1 Variable 'StringToCheck' hides a variable in an enclosing block. C:\Users\family\AppData\Local\Temporary Projects\WindowsApplication1\Form2.vb 62 18 WindowsApplication1

       Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    
    
    
            Dim StringToCheck As New StringBuilder() ' ****
    
            For Each StringToCheck As String In Form1.ResultSecondLine
    
                StringToCheck = StringToCheck.Replace(vbCrLf, ",").Remove(StringToCheck.Length - 1, 1)
    
                Dim StringsToCheck As String() = StringToCheck.ToString.Split(","c) ' ****
    
    
                For Each S As String In StringsToCheck
    
                    Dim StringsToFind As String() = {S(0) & S(1), _
                                                         S(0) & S(2), _
                                                         S(0) & S(3), _
                                                         S(1) & S(2), _
                                                         S(1) & S(3), _
                                                         S(2) & S(3)}
    
                    For Each Find As String In StringsToFind
                        Dim Count As Integer = 0
                        For Each Check As String In StringsToCheck
                            If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) Then Count += 1
                        Next
    
                        Dim sb As StringBuilder = New StringBuilder()
                        Dim f As New StringBuilderFinder(sb, Find)
    
                        If f.SearchAndAppend(Find) Then
    
                            sb.Append(f)
    
                            TextBox3.AppendText(sb.ToString & vbCrLf)
                        End If
                    Next
                Next
            Next
    
        End Sub
    End Class
    Public Class StringBuilderFinder
    
        Private sb As StringBuilder
        Private text As String
    
        Public Sub New(sb As StringBuilder, textToFind As String)
            Me.sb = sb
            text = textToFind
        End Sub
    
        Public Function SearchAndAppend(Find As String) As Boolean
            sb.Append(Find)
            Return Find.Contains(text)
        End Function
    End Class

    thank All.

    Friday, May 11, 2018 4:02 AM

Answers

  • Error 1 Value of type 'String' cannot be converted to 'System.Text.StringBuilder'. C:\Users\family\AppData\Local\Temporary Projects\WindowsApplication1\Form2.vb 62 52 WindowsApplication1.

    If you want to use a string builder in that line of code then you need to ensure that Form1.ResultSecondLine is a collection of string builders.  You haven't shown the code that creates Form1.ResultSecondLine.

    You can't just substitute a string builder for a string - they are different objects with different properties and different methods.

    A string builder will improve performance where you are making many changes to a string.  Your code is slow because it is examining strings in nested loops, and a string builder is unlikely to help with that.  If you use a string builder for the text box text you should not be appending to the existing text in the text box - keep a copy of the text box text in the string builder, append to the string builder in the loop, and copy the whole string builder to the text box text.

    • Marked as answer by mipakteh Sunday, May 13, 2018 12:31 PM
    • Unmarked as answer by mipakteh Sunday, May 13, 2018 12:31 PM
    • Marked as answer by mipakteh Sunday, May 13, 2018 12:34 PM
    Friday, May 11, 2018 5:15 AM
  • This seems to be a continuation of the problem you have been trying to solve for the past six months.

    Until you can explain in plain words what you are trying to achieve we are still guessing at the objective.

    Based on what you show here in this thread, it appears you want to:

    "Find all unique combinations of two-digits within a list of four-digit numbers then count the number of four-digit numbers which contain both digits from the unique two-digit list."

    Using the code you have supplied, I've written the following example.  This example code was written the way it is for clarity.  I've tried to mirror your intended logic (as I understand it) so that you can follow what I have done in accordance with what you have tried to do.

    In this example, "DataTextFile.txt" contains the "text file three lines" that you posted in this thread.

    Public Class Form1
        Friend WithEvents OutputTextBox As New RichTextBox With {.Dock = DockStyle.Fill}
        Friend WithEvents ExecuteButton As New Button With {.AutoSize = True, .Dock = DockStyle.Top, .Text = "Execute"}
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Controls.Add(OutputTextBox)
            Controls.Add(ExecuteButton)
        End Sub
    
        Private Sub ExecuteButton_Click(sender As Object, e As EventArgs) Handles ExecuteButton.Click
            Dim fourDigitList As List(Of String) = ReadFileIntoFourDigitStringList("DataTextFile.txt")
            Dim twoDigitHashset As HashSet(Of String) = GetDistinctTwoDigitStrings(fourDigitList)
            Dim results As Dictionary(Of String, Integer) = CountTwoDigitInstacesInFourDigitStrings(fourDigitList, twoDigitHashset)
            For Each key In New SortedSet(Of String)(results.Keys)
                OutputTextBox.AppendText($"{key} = {results(key)}{vbCrLf}")
            Next
        End Sub
    
        Private Function ReadFileIntoFourDigitStringList(filePath As String) As List(Of String)
            Dim result As New List(Of String)
            For Each line In IO.File.ReadAllLines(filePath)
                result.AddRange(line.Split(","))
            Next
            Return result
        End Function
    
        Private Function GetDistinctTwoDigitStrings(fourDigitList As List(Of String)) As HashSet(Of String)
            Dim result As New HashSet(Of String)
            For Each fourDigitString In fourDigitList
                Dim permutation1 As String = fourDigitString(0) & fourDigitString(1)
                Dim permutation2 As String = fourDigitString(0) & fourDigitString(2)
                Dim permutation3 As String = fourDigitString(0) & fourDigitString(3)
                Dim permutation4 As String = fourDigitString(1) & fourDigitString(2)
                Dim permutation5 As String = fourDigitString(1) & fourDigitString(3)
                Dim permutation6 As String = fourDigitString(2) & fourDigitString(3)
                If Not result.Contains(permutation1) Then result.Add(permutation1)
                If Not result.Contains(permutation2) Then result.Add(permutation2)
                If Not result.Contains(permutation3) Then result.Add(permutation3)
                If Not result.Contains(permutation4) Then result.Add(permutation4)
                If Not result.Contains(permutation5) Then result.Add(permutation5)
                If Not result.Contains(permutation6) Then result.Add(permutation6)
            Next
            Return result
        End Function
    
        Private Function CountTwoDigitInstacesInFourDigitStrings(fourDigitList As List(Of String), twoDigitHashset As HashSet(Of String)) As Dictionary(Of String, Integer)
            Dim result As New Dictionary(Of String, Integer)
            For Each fourDigitString In fourDigitList
                For Each twoDigitString In twoDigitHashset
                    If fourDigitString.Contains(twoDigitString(0)) AndAlso fourDigitString.Contains(twoDigitString(1)) Then
                        If result.ContainsKey(twoDigitString) Then
                            result(twoDigitString) += 1
                        Else
                            result(twoDigitString) = 1
                        End If
                    End If
                Next
            Next
            Return result
        End Function
    End Class

    The output of this code is:

    00 = 21
    01 = 5
    02 = 8
    03 = 5
    04 = 2
    05 = 8
    06 = 11
    07 = 6
    08 = 2
    09 = 6
    10 = 5
    11 = 22
    13 = 4
    14 = 4
    15 = 9
    16 = 5
    17 = 5
    18 = 8
    19 = 11
    20 = 8
    21 = 4
    22 = 22
    23 = 4
    24 = 7
    25 = 8
    26 = 8
    27 = 7
    28 = 3
    29 = 7
    30 = 5
    31 = 4
    32 = 4
    33 = 19
    35 = 6
    36 = 7
    37 = 7
    38 = 5
    39 = 2
    41 = 4
    42 = 7
    43 = 5
    44 = 20
    45 = 7
    46 = 8
    47 = 8
    48 = 3
    49 = 7
    50 = 8
    51 = 9
    52 = 8
    53 = 6
    54 = 7
    55 = 31
    56 = 5
    57 = 9
    58 = 9
    59 = 10
    60 = 11
    61 = 5
    62 = 8
    63 = 7
    64 = 8
    65 = 5
    66 = 24
    67 = 8
    68 = 3
    69 = 7
    70 = 6
    71 = 5
    72 = 7
    73 = 7
    74 = 8
    75 = 9
    76 = 8
    77 = 26
    78 = 8
    79 = 7
    80 = 2
    81 = 8
    82 = 3
    83 = 5
    85 = 9
    86 = 3
    87 = 8
    88 = 20
    89 = 6
    90 = 6
    91 = 11
    92 = 7
    94 = 7
    95 = 10
    96 = 7
    97 = 7
    98 = 6
    99 = 26


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    • Proposed as answer by Mr. Monkeyboy Saturday, May 12, 2018 6:27 PM
    • Edited by Reed KimbleMVP, Moderator Saturday, May 12, 2018 6:39 PM reworded objective to be more descriptively accurate
    • Marked as answer by mipakteh Sunday, May 13, 2018 12:29 PM
    Saturday, May 12, 2018 5:37 PM
    Moderator

All replies

  • Error 1 Variable 'StringToCheck' hides a variable in an enclosing block. C:\Users\family\AppData\Local\Temporary Projects\WindowsApplication1\Form2.vb 62 18 WindowsApplication1

    You have defined the variable twice - once as a StringBuilder and once as a string.

    Change
            Dim StringToCheck As New StringBuilder() ' ****
            For Each StringToCheck As String In Form1.ResultSecondLine

    to

            For Each StringToCheck As StringBuilder In Form1.ResultSecondLine

    If the error occurs on that first line then you have another declaration for the same variable at the form level.   You almost certainly do not want to use a StringBuilder in this example.

    Friday, May 11, 2018 4:19 AM
  • Hi Acamar,

    1. If I use ,

     For Each StringToCheck As StringBuilder In Form1.ResultSecondLine then Error

    Error 1 Value of type 'String' cannot be converted to 'System.Text.StringBuilder'. C:\Users\family\AppData\Local\Temporary Projects\WindowsApplication1\Form2.vb 62 52 WindowsApplication1.

    2. If I use,

     For Each StringToCheck As String In Form1.ResultSecondLine then the Result show like this;

    if not use stringBuilder speed very slow.


    Friday, May 11, 2018 4:51 AM
  • Error 1 Value of type 'String' cannot be converted to 'System.Text.StringBuilder'. C:\Users\family\AppData\Local\Temporary Projects\WindowsApplication1\Form2.vb 62 52 WindowsApplication1.

    If you want to use a string builder in that line of code then you need to ensure that Form1.ResultSecondLine is a collection of string builders.  You haven't shown the code that creates Form1.ResultSecondLine.

    You can't just substitute a string builder for a string - they are different objects with different properties and different methods.

    A string builder will improve performance where you are making many changes to a string.  Your code is slow because it is examining strings in nested loops, and a string builder is unlikely to help with that.  If you use a string builder for the text box text you should not be appending to the existing text in the text box - keep a copy of the text box text in the string builder, append to the string builder in the loop, and copy the whole string builder to the text box text.

    • Marked as answer by mipakteh Sunday, May 13, 2018 12:31 PM
    • Unmarked as answer by mipakteh Sunday, May 13, 2018 12:31 PM
    • Marked as answer by mipakteh Sunday, May 13, 2018 12:34 PM
    Friday, May 11, 2018 5:15 AM
  • Well the below code constantly creates a new stringbuilder in a For/Next which doesn't make sense. I suspect that it should be created outside the For/Next and used in the For/Next. Then when the For/Next has completed append all the string to the TextBox rather than appending string by string to a TextBox which slows down the process having to write to update the UI constantly.

    And the Function StringBuilderFinder doesn't seem to perform much that couldn't be performed directly in the loops either. There would be some time for the loops to wait on the function to return.

    For Each Find As String In StringsToFind
                        Dim Count As Integer = 0
                        For Each Check As String In StringsToCheck
                            If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) Then Count += 1
                        Next
    
                        Dim sb As StringBuilder = New StringBuilder()
                        Dim f As New StringBuilderFinder(sb, Find)
    
                        If f.SearchAndAppend(Find) Then
    
                            sb.Append(f)
    
                            TextBox3.AppendText(sb.ToString & vbCrLf)
                        End If
                    Next


    La vida loca

    Friday, May 11, 2018 4:06 PM
  • Acamar please correct this code.

    Option Strict On
    Option Infer Off
    Option Explicit On
    
    Imports System.IO
    Imports System.Data
    Imports System.Text
    
    
    Public Class Form1
    
    
        Public ResultSecondLine As New List(Of String)
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    
            'Textfile ThreeLines = 9600,4154,2972,5595,7086,2947,5915,7463,2233,3897,3955,8868,9819,0025,6330,8558,6750,7855,6941,7531,0603,5496,1785
            '4627,5223,9959,6243,1878,5062,9679,1898,4857,1031,5957,6027,2207,1565,9258,2577,2890,1703,1813,6062,3387,4583,6201
            '5254,4487,3650,8151,7743,0195,2452,7691,4643,5990,1990,3557,7494,7052,8155,6382,0469,2491,7664,9214,5918,0544,9261
    
            Dim sr As New System.IO.StreamReader("C:\Users\family\Documents\ThreeLines.txt")
    
            Do While sr.Peek <> -1
                Dim StringTxt As String = sr.ReadToEnd
                TextBox1.AppendText(StringTxt & vbCrLf)
                ResultSecondLine.Add(StringTxt)
            Loop
    
        End Sub
    
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Form2.Show()
        End Sub
    
    End Class
    
    Imports System.Text
    
    Public Class Form2
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    
            Dim StringToCheck As New StringBuilder() ' ****
    
            For I As Integer = 0 To Form1.ResultSecondLine.Count - 1
                StringToCheck.AppendLine(Form1.ResultSecondLine(I).ToString)
            Next I
    
            StringToCheck = StringToCheck.Replace(vbCrLf, ",").Remove(StringToCheck.Length - 1, 1)
    
            Dim StringsToCheck As String() = StringToCheck.ToString.Split(","c) ' ****
    
            For Each S As String In StringsToCheck
                TextBox1.AppendText(S.ToString)
    
                Dim StringsToFind As String() = {S(0) & S(1), _
                                                     S(0) & S(2), _
                                                     S(0) & S(3), _
                                                     S(1) & S(2), _
                                                     S(1) & S(3), _
                                                     S(2) & S(3)}
    
                For Each Find As String In StringsToFind
                    Dim Count As Integer = 0
                    For Each Check As String In StringsToCheck
                        If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) Then Count += 1
                    Next
    
                    Dim sb As StringBuilder = New StringBuilder()
                    Dim f As New StringBuilderFinder(sb, Find)
    
                    If f.SearchAndAppend(Find) Then
    
                        sb.Append(f)
    
                        TextBox2.AppendText(sb.ToString & vbCrLf)
                    End If
                Next
            Next
    
        End Sub
    
    End Class
    
    Public Class StringBuilderFinder
    
        Private sb As StringBuilder
        Private text As String
    
        Public Sub New(sb As StringBuilder, textToFind As String)
            Me.sb = sb
            text = textToFind
        End Sub
    
        Public Function SearchAndAppend(Find As String) As Boolean
            sb.Append(Find)
            Return Find.Contains(text)
        End Function
    End Class
    
    

    Saturday, May 12, 2018 3:44 AM
  • something wrong in StringBuilderFinder.

    thank Mr.Mon

    Saturday, May 12, 2018 3:47 AM
  • This seems to be a continuation of the problem you have been trying to solve for the past six months.

    Until you can explain in plain words what you are trying to achieve we are still guessing at the objective.

    Based on what you show here in this thread, it appears you want to:

    "Find all unique combinations of two-digits within a list of four-digit numbers then count the number of four-digit numbers which contain both digits from the unique two-digit list."

    Using the code you have supplied, I've written the following example.  This example code was written the way it is for clarity.  I've tried to mirror your intended logic (as I understand it) so that you can follow what I have done in accordance with what you have tried to do.

    In this example, "DataTextFile.txt" contains the "text file three lines" that you posted in this thread.

    Public Class Form1
        Friend WithEvents OutputTextBox As New RichTextBox With {.Dock = DockStyle.Fill}
        Friend WithEvents ExecuteButton As New Button With {.AutoSize = True, .Dock = DockStyle.Top, .Text = "Execute"}
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Controls.Add(OutputTextBox)
            Controls.Add(ExecuteButton)
        End Sub
    
        Private Sub ExecuteButton_Click(sender As Object, e As EventArgs) Handles ExecuteButton.Click
            Dim fourDigitList As List(Of String) = ReadFileIntoFourDigitStringList("DataTextFile.txt")
            Dim twoDigitHashset As HashSet(Of String) = GetDistinctTwoDigitStrings(fourDigitList)
            Dim results As Dictionary(Of String, Integer) = CountTwoDigitInstacesInFourDigitStrings(fourDigitList, twoDigitHashset)
            For Each key In New SortedSet(Of String)(results.Keys)
                OutputTextBox.AppendText($"{key} = {results(key)}{vbCrLf}")
            Next
        End Sub
    
        Private Function ReadFileIntoFourDigitStringList(filePath As String) As List(Of String)
            Dim result As New List(Of String)
            For Each line In IO.File.ReadAllLines(filePath)
                result.AddRange(line.Split(","))
            Next
            Return result
        End Function
    
        Private Function GetDistinctTwoDigitStrings(fourDigitList As List(Of String)) As HashSet(Of String)
            Dim result As New HashSet(Of String)
            For Each fourDigitString In fourDigitList
                Dim permutation1 As String = fourDigitString(0) & fourDigitString(1)
                Dim permutation2 As String = fourDigitString(0) & fourDigitString(2)
                Dim permutation3 As String = fourDigitString(0) & fourDigitString(3)
                Dim permutation4 As String = fourDigitString(1) & fourDigitString(2)
                Dim permutation5 As String = fourDigitString(1) & fourDigitString(3)
                Dim permutation6 As String = fourDigitString(2) & fourDigitString(3)
                If Not result.Contains(permutation1) Then result.Add(permutation1)
                If Not result.Contains(permutation2) Then result.Add(permutation2)
                If Not result.Contains(permutation3) Then result.Add(permutation3)
                If Not result.Contains(permutation4) Then result.Add(permutation4)
                If Not result.Contains(permutation5) Then result.Add(permutation5)
                If Not result.Contains(permutation6) Then result.Add(permutation6)
            Next
            Return result
        End Function
    
        Private Function CountTwoDigitInstacesInFourDigitStrings(fourDigitList As List(Of String), twoDigitHashset As HashSet(Of String)) As Dictionary(Of String, Integer)
            Dim result As New Dictionary(Of String, Integer)
            For Each fourDigitString In fourDigitList
                For Each twoDigitString In twoDigitHashset
                    If fourDigitString.Contains(twoDigitString(0)) AndAlso fourDigitString.Contains(twoDigitString(1)) Then
                        If result.ContainsKey(twoDigitString) Then
                            result(twoDigitString) += 1
                        Else
                            result(twoDigitString) = 1
                        End If
                    End If
                Next
            Next
            Return result
        End Function
    End Class

    The output of this code is:

    00 = 21
    01 = 5
    02 = 8
    03 = 5
    04 = 2
    05 = 8
    06 = 11
    07 = 6
    08 = 2
    09 = 6
    10 = 5
    11 = 22
    13 = 4
    14 = 4
    15 = 9
    16 = 5
    17 = 5
    18 = 8
    19 = 11
    20 = 8
    21 = 4
    22 = 22
    23 = 4
    24 = 7
    25 = 8
    26 = 8
    27 = 7
    28 = 3
    29 = 7
    30 = 5
    31 = 4
    32 = 4
    33 = 19
    35 = 6
    36 = 7
    37 = 7
    38 = 5
    39 = 2
    41 = 4
    42 = 7
    43 = 5
    44 = 20
    45 = 7
    46 = 8
    47 = 8
    48 = 3
    49 = 7
    50 = 8
    51 = 9
    52 = 8
    53 = 6
    54 = 7
    55 = 31
    56 = 5
    57 = 9
    58 = 9
    59 = 10
    60 = 11
    61 = 5
    62 = 8
    63 = 7
    64 = 8
    65 = 5
    66 = 24
    67 = 8
    68 = 3
    69 = 7
    70 = 6
    71 = 5
    72 = 7
    73 = 7
    74 = 8
    75 = 9
    76 = 8
    77 = 26
    78 = 8
    79 = 7
    80 = 2
    81 = 8
    82 = 3
    83 = 5
    85 = 9
    86 = 3
    87 = 8
    88 = 20
    89 = 6
    90 = 6
    91 = 11
    92 = 7
    94 = 7
    95 = 10
    96 = 7
    97 = 7
    98 = 6
    99 = 26


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    • Proposed as answer by Mr. Monkeyboy Saturday, May 12, 2018 6:27 PM
    • Edited by Reed KimbleMVP, Moderator Saturday, May 12, 2018 6:39 PM reworded objective to be more descriptively accurate
    • Marked as answer by mipakteh Sunday, May 13, 2018 12:29 PM
    Saturday, May 12, 2018 5:37 PM
    Moderator
  • After re-reading my post, even I didn't like the wording of the objective.  The post has been edited to be more descriptive of the intent.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Saturday, May 12, 2018 6:39 PM
    Moderator
  • thank Reed Kimble,

    error list appear before debug.

    Error 1 Character is not valid. C:\Users\family\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 23 38 WindowsApplication1

     For Each key In New SortedSet(Of String)(results.Keys)
                OutputTextBox.AppendText($"{key} = {results(key)}{vbCrLf}")
     Next

    At $.

    Sunday, May 13, 2018 12:02 AM
  • I think it ok.

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Imports System.IO
    Imports System.Data
    Imports System.Windows.Forms
    
    
    Public Class Form1
        Friend WithEvents OutputTextBox As New RichTextBox With {.Dock = DockStyle.Fill}
        Friend WithEvents ExecuteButton As New Button With {.AutoSize = True, .Dock = DockStyle.Top, .Text = "Execute"}
    
    
    
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Controls.Add(OutputTextBox)
            Controls.Add(ExecuteButton)
    
        End Sub
    
    
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim fourDigitList As List(Of String) = ReadFileIntoFourDigitStringList("C:\Users\family\Documents\C.txt")
            Dim twoDigitHashset As HashSet(Of String) = GetDistinctTwoDigitStrings(fourDigitList)
            Dim results As Dictionary(Of String, Integer) = CountTwoDigitInstacesInFourDigitStrings(fourDigitList, twoDigitHashset)
            For Each key As String In New SortedSet(Of String)(results.Keys)
                OutputTextBox.AppendText(key & " = " & results(key) & vbCrLf)
    
            Next
    
        End Sub
    
        Private Function ReadFileIntoFourDigitStringList(filePath As String) As List(Of String)
            Dim result As New List(Of String)
            For Each line As String In IO.File.ReadAllLines(filePath)
                result.AddRange(line.Split(CChar(",")))
            Next
            Return result
        End Function
    
        Private Function GetDistinctTwoDigitStrings(fourDigitList As List(Of String)) As HashSet(Of String)
            Dim result As New HashSet(Of String)
            For Each fourDigitString As String In fourDigitList
                Dim permutation1 As String = fourDigitString(0) & fourDigitString(1)
                Dim permutation2 As String = fourDigitString(0) & fourDigitString(2)
                Dim permutation3 As String = fourDigitString(0) & fourDigitString(3)
                Dim permutation4 As String = fourDigitString(1) & fourDigitString(2)
                Dim permutation5 As String = fourDigitString(1) & fourDigitString(3)
                Dim permutation6 As String = fourDigitString(2) & fourDigitString(3)
                If Not result.Contains(permutation1) Then result.Add(permutation1)
                If Not result.Contains(permutation2) Then result.Add(permutation2)
                If Not result.Contains(permutation3) Then result.Add(permutation3)
                If Not result.Contains(permutation4) Then result.Add(permutation4)
                If Not result.Contains(permutation5) Then result.Add(permutation5)
                If Not result.Contains(permutation6) Then result.Add(permutation6)
            Next
            Return result
        End Function
    
        Private Function CountTwoDigitInstacesInFourDigitStrings(fourDigitList As List(Of String), twoDigitHashset As HashSet(Of String)) As Dictionary(Of String, Integer)
            Dim result As New Dictionary(Of String, Integer)
            For Each fourDigitString As String In fourDigitList
                For Each twoDigitString As String In twoDigitHashset
                    If fourDigitString.Contains(twoDigitString(0)) AndAlso fourDigitString.Contains(twoDigitString(1)) Then
                        If result.ContainsKey(twoDigitString) Then
                            result(twoDigitString) += 1
                        Else
                            result(twoDigitString) = 1
                        End If
                    End If
                Next
            Next
            Return result
        End Function
    
    
    End Class
    

    Sunday, May 13, 2018 3:30 AM
  • Yes the correction you made is fine.  You must not be using VS2017, which is why you got that error.  I was using the new inline string formatting, which is not available on previous versions.

    Is that the output you wanted?  Does the code sample help solve your issue?


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by mipakteh Sunday, May 13, 2018 8:36 AM
    • Unmarked as answer by mipakteh Sunday, May 13, 2018 12:29 PM
    Sunday, May 13, 2018 8:28 AM
    Moderator
  • yes,correct Reed Kimble.
    Sunday, May 13, 2018 8:36 AM
  • Thank Acamar............................................................................
    Sunday, May 13, 2018 8:38 AM
  • thank Acamar
    Sunday, May 13, 2018 8:39 AM
  • OK, good, glad it was helpful.

    Could you please do me a favor and change the answer you marked?  It would be better to select the post with the code (proposed by MrMonkeyBoy) rather than the follow-up post.

    You might also mark the information provided by Acamar since it was relevant to the original question about a StringBuilder (even though the eventual solution did not involve a StringBuilder).

    Thanks!


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Sunday, May 13, 2018 8:45 AM
    Moderator
  • ok, thank

    Sunday, May 13, 2018 12:34 PM