如何将文本替换为textbox2而不是替换textbox1中的实际文本?(VB.NET) [英] How to replace text to textbox2 instead of replacing the actual text in textbox1?(VB.NET)

查看:118
本文介绍了如何将文本替换为textbox2而不是替换textbox1中的实际文本?(VB.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中演示简单加密。在这部分中,我应该将textbox1中的每个字符替换为指定的特殊字符。但是在这段代码中,实际的文本被替换了,我不希望这种情况发生,而是希望在textbox2中显示,保留textbox1中的实际文本。我怎么能这样做?



这是代码:



I'm trying to demonstrate easy encryption in my project. In this part, i'm supposed to replace each character in textbox1 to special characters assigned. But in this code the actual text gets replaced, I don't want that to happen,instead I want that to be shown in textbox2 retaining actual text in textbox1. How can I do that?

Here is the code:

Private arLetterChars() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 "
    Private arEncryptedChars() As Char = "¿ɸ¢ç¶‹!˜Ö´åÄÚᴁÍìæ¯~[Ûÿ|ÑûÏÉí³èô§ŠÀÙ:ÒÓ?>þ.äƒ%*š¾†±♠}@æŒ#/{۞],"
    '// encrypt.
    Private Sub Btnaddenc_Click(sender As System.Object, e As System.EventArgs) Handles BtnAddEnc.Click
        With Textbox1
            For Each myTextBoxChar As Char In Textbox1.Text '// loop thru TextBox, one char. at a time.
                For i As Integer = 0 To arLetterChars.Length - 1 '// loop thru all letters in the Array.
                    '// if TextBox char ='s the char in your Array, replace the TextBox char with the same #'ed Array char of the Encrypted letters.
                    If myTextBoxChar = arLetterChars(i) Then Textbox1.Text = Textbox1.Text.Replace(myTextBoxChar, arEncryptedChars(i))
                Next
            Next
        End With
    End Sub

推荐答案

如果您不想影响Textbox1,请不要分配给它...

更改

If you don't want to affect Textbox1, then don't assign to it...
Change
If myTextBoxChar = arLetterChars(i) Then Textbox1.Text = Textbox1.Text.Replace(myTextBoxChar, arEncryptedChars(i))



To

If myTextBoxChar = arLetterChars(i) Then Textbox2.Text = Textbox1.Text.Replace(myTextBoxChar, arEncryptedChars(i))


这篇关于如何将文本替换为textbox2而不是替换textbox1中的实际文本?(VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆