我想从条形码中的字符串中提取字符:
<TextBox x:Name="Original_Code_TxtBox"
Text="£C131020019969120792A32305VPFE193015"/>
我想要:仅A32305VPFE1
部分。但事实是,此字符串永远不会具有相同的长度。可以是:A32305
或A32305F
...
那么我该如何编写类似于以下代码的代码:
private void Delimite_Btn_Click(object sender, RoutedEventArgs e)
{
int beginstring = 20;
int endstring = Original_Code_TxtBox.Text.Length - 5; // because the last 5 characters never change
Original_Code_TxtBox.Select(beginstring, endstring);
}
答案 0 :(得分:0)
private static readonly int beginIndex = 20;
private void Delimite_Btn_Click(object sender, RoutedEventArgs e)
{
string barcode = Original_Code_TxtBox.Text;
int endIndex = barcode.Length - 5;
if (endIndex > beginIndex)
{
var selectedText = barcode.Substring(beginIndex, endIndex - beginIndex);
}
}
答案 1 :(得分:-1)