如何以窗口形式处理字符串 [英] How to process the string in window form

查看:53
本文介绍了如何以窗口形式处理字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 string original =  ; 
string encrypted = ;
char key = ' x';

getline(cin,original);
cout<< 原始数据=<<原始<< endl<< ENDL;
cout<< 加密数据=;

for int temp = 0 ; temp< original.size(); temp ++)
{
w = ' A';
x = ' B';
y = ' C';
encrypted + = original [temp] ^( int (key)* temp - int ( key)/(temp + 1))% 255 ;
z = ' Z';
cout<< w<< x<< y<<加密的<< Z者除外;
}
cout<< endl;



以上是我的控制台应用程序的代码,现在我想制作一个GUI,但我如何以窗口形式编程呢?



我创建了一个richTextbox1来询问用户输入文本,然后尝试像上面的控制台一样处理

应用程序(加密+ =原始[temp] ^(int(key) * temp - int(key)/(temp + 1))%255;)



String ^ Data1;

String ^ Data = richTextBox1 - >文字;

for(int i = 0; i< 10; i ++)

{

Data1 + = Data [i];

}

MessageBox :: Show(Data1);

}





当我运行它时,我在Box中键入文本,然后单击按钮然后我编程如上,它出现了一个问题,说IndexOutOfRangeExxeption未处理



是什么意思?

请问任何1帮我转换这个控制台代码到窗口表单代码,我是窗口形式的新手,没有太多教程,请帮助我〜



提前Thx。希望大家都明白我的英语和我的问题。

解决方案

唯一的问题是:你的代码不能保证字符串 Data 的长度为10或更多,这是添加到原始字符串所必需的。如果您输入10个或更多字符,它将起作用。无论如何,像10这样的直接常数的硬编码总是很糟糕。



我回答了你的主要问题,但你的帖子的其余部分包含很多非常模糊的时刻;我只是不想解决所有问题。你怎么能用Forms编程呢?什么? (谁知道你的控制台应用程序的目的?无论如何,尽量不要将管理的ref类型与 std :: 库混合。)你的意思是怎么样?通过做一些努力工作。这不是一个真正的问题。



带循环的代码有一个问题:你反复使用字符串连接,这对于性能来说真的很糟糕。你知道字符串不可变。每次进行连接时,都会创建一个全新的字符串,并复制所有数据以对其进行初始化。对于连接,您需要使用 System :: Text :: StringBuilder



-SA

string original = "";
string encrypted = "";
char key = 'x';

getline (cin, original);
cout << "Original data = " << original << endl << endl;
cout << "Encrypted Data = " ;

 for (int temp = 0; temp < original.size(); temp++)
 {
	w = 'A';
	x = 'B';
	y = 'C';
  encrypted += original[temp] ^ (int(key) * temp - int(key) / (temp+1)) % 255;
    z = 'Z';
	cout << w << x << y << encrypted << z;
 }
 cout << endl;


Above is the code of my console application, now i want to make a GUI but how can i program it in window form?

I created a richTextbox1 to ask user enter the text, then try to process like above console
application ( encrypted += original[temp] ^ (int(key) * temp - int(key) / (temp+1)) % 255;)

String ^ Data1;
String ^ Data = richTextBox1 -> Text;
for (int i=0 ; i < 10 ; i++)
{
Data1 += Data[i];
}
MessageBox :: Show(Data1);
}


when i run it, i type text in the Box, and click the button then i program as above, it come out a problem said "IndexOutOfRangeExxeption was unhandled"

What is it mean?
Do any1 help me to convert this console code to window form code, i am very new in window form, and no much tutorial, plz help me~

Thx in advance. Hope You all understand my english and also my problem.

解决方案

The only problem is: your code does not guarantee that the string Data has the length of 10 or more, which is required to add to the original string. If you type 10 characters or more, it will work. Anyway, hard-coding of immediate constants like 10 is always bad.

I answered your main question, but the rest of your post contains a lot of very vague moments; I just don''t want to address them all. How can you program it in Forms? What it? (Who knows the purpose of your console application? Anyway, try not to mix managed "ref" types with std:: library.) What do you mean "how"? By doing some hard work. Not a real question.

One problem with the code with cycle: you use string concatenation repeatedly, which is really bad for performance. Do you know that strings are immutable. Each time you do concatenation, a brand new string is created and all data is copied to initialize it. For concatenation, you need to use System::Text::StringBuilder.

—SA


这篇关于如何以窗口形式处理字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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