[英]Getting Char From Position in C# textbox
我正在尝试从文本框中获取3个字符->例如:“ test”并从此文本中获取3个字符。
我正在尝试类似的操作,其中printer1_logo.text是另一个文本框,我想从文本框RefrenceNumber获得4个字符。
Printer1_Logo.Text=RefrenceNumber.GetCharFromPosition(4);
错误:
Argument 1: cannot convert from 'int' to 'System.Drawing.Point' (CS1503) - D:\App\MainForm.cs:249,66
The best overloaded method match for 'System.Windows.Forms.TextBoxBase.GetCharFromPosition(System.Drawing.Point)' has some invalid arguments (CS1502) - D:\App\MainForm.cs:249,31
在C#中, textBox1.Text = textBox2.Text[2].ToString()
在VB中, textBox1.Text = textBox2.Text(2).ToString
如果您需要超过1个字符
textBox1.Text = textBox2.Text.SubString(2,2)
GetCharFomPosition(位置表示坐标。不是char索引),您还可以使用string作为char数组,例如:
Char theChar = Printer1_Logo.Text[2]; // index is start at 0
您可以简单地使用SubString从字符串中切出:
string subString1 = textbox1.Text.Substring(0,3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.