Skip to content

Instantly share code, notes, and snippets.

@Laicure
Last active February 3, 2016 15:27
Show Gist options
  • Save Laicure/f98f35c0ea6a5b5dcff2 to your computer and use it in GitHub Desktop.
Save Laicure/f98f35c0ea6a5b5dcff2 to your computer and use it in GitHub Desktop.
[vb] String Manipulator Snippets
Imports System.Text
Module StringManipulate
#Region "Code Generator"
Public Function CodeGen(sizer As Integer, customString As String) As String
Dim charX As String = IIf(String.IsNullOrWhiteSpace(customString), "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz", customString).ToString
Dim Rand As New Random
Dim BuildMe As New StringBuilder
Dim idx, CodeSize, charXsize As Integer
charXsize = charX.Length
CodeSize = sizer
For i As Integer = 1 To CodeSize
idx = Rand.Next(0, charXsize)
BuildMe.Append(charX.Substring(idx, 1))
Next
Return BuildMe.ToString
End Function
#End Region
#Region "Character Duplicate Remover"
Public Function CharDupRemove(strx As String) As String
Dim x() As Char = strx.ToCharArray
Dim y As Generic.List(Of Char)
y = x.Distinct.ToList
Return String.Join("", y.ToArray)
End Function
#End Region
#Region "ListBox Items to Array String"
Friend Function ListBoxToArray(ListBoxer As ListBox) As String()
Dim arr As String() = {"*"}
If ListBoxer.Items.Count > 0 Then
arr = New String(ListBoxer.Items.Count - 1) {}
For i As Integer = 0 To ListBoxer.Items.Count - 1
arr(i) = ListBoxer.Items(i).ToString
Next
End If
Return arr
End Function
#End Region
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment