3
Contributors
7
Replies
32
Views
3 Years
Discussion Span
Last Post by schroaus
Featured Replies
  • If you mean like changing "My Label" to "xxxxxxxx" then you could try lblLabel.Text = Space(lblLabel.Text.Length).Replace(" ", "x") `Space(lblLabel.Text.Length)` generates a string of blanks the same length as the label text and `Replace(" ","x")` replaces all of the blanks with the desired character. Read More

  • You could use a readonly textbox then set the password character, by removing the border it looks just like a label. Read More

  • You could use regular expressions Dim rex As New System.Text.RegularExpressions.Regex("[^ ]") lblMylabel.Text = rex.Replace(lblMylabel.Text, "x") The expression **"[^ ]"** matches any non-blank character. **Rex.Replace** scans the given string and replaces any matching string with the second string so basically it says **replace any non-blank character with an x.** Read More

  • Or if you want each word to have a different letter mask You could use the split function, change each word to the character you want and use the join function to put it back together. Or if you want a simple substitution cipher the Caesar cipher is easy to … Read More

  • Here's examples of both: Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim OrigStr As String = "Test1 Test2 Test3" 'Using Split Dim MaskStr As String = "xdfeotjdwps" Dim OrigSplit() As String = OrigStr.Split() For I = 0 To OrigSplit.Length - 1 OrigSplit(I) = Space(OrigSplit(I).Length).Replace(" ", MaskStr(I)) Next … Read More

1

If you mean like changing "My Label" to "xxxxxxxx" then you could try

lblLabel.Text = Space(lblLabel.Text.Length).Replace(" ", "x")

Space(lblLabel.Text.Length) generates a string of blanks the same length as the label text and Replace(" ","x") replaces all of the blanks with the desired character.

Edited by Reverend Jim

1

You could use a readonly textbox then set the password character, by removing the border it looks just like a label.

0

I need to be able to change the text within the labels to a desired character. I can not use the password character, because the character is not consistant. It must also be able to ignore the spaces withing the label.

1

You could use regular expressions

Dim rex As New System.Text.RegularExpressions.Regex("[^ ]")
lblMylabel.Text = rex.Replace(lblMylabel.Text, "x")

The expression "[^ ]" matches any non-blank character. Rex.Replace scans the given string and replaces any matching string with the second string so basically it says replace any non-blank character with an x.

1

Or if you want each word to have a different letter mask You could use the split function, change each word to the character you want and use the join function to put it back together.

Or if you want a simple substitution cipher the Caesar cipher is easy to implement and will change each character to an offset character.

1

Here's examples of both:

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim OrigStr As String = "Test1 Test2 Test3"

        'Using Split

        Dim MaskStr As String = "xdfeotjdwps"
        Dim OrigSplit() As String = OrigStr.Split()
        For I = 0 To OrigSplit.Length - 1
            OrigSplit(I) = Space(OrigSplit(I).Length).Replace(" ", MaskStr(I))
        Next
        Label2.Text = Join(OrigSplit)

        'Using Caesar Cipher

        Label1.Text = CaesarCipher(OrigStr, "Test123")
    End Sub
    Private Function CaesarCipher(Input As String, KeyStr As String) As String
        Dim Key As Integer = 0
        For Each c As Char In KeyStr
            Key += Asc(c)
        Next
        Dim Result As String = ""
        If Key > 93 Then Math.DivRem(Key, 93, Key)
        For Each c As Char In Input
            If c <> " " Then
                Dim offset As Integer = Key + Asc(c)
                If offset > 125 Then offset = (offset - 125) + 32
                Result += Chr(offset)
            Else
                Result += c
            End If
        Next
        Return Result
    End Function

Edited by tinstaafl

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.