如何在if条件下使用split条件 [英] how to use split condition in if condition
问题描述
我有listview项目为
COLUMN1
IN 123
OU 234
当我双击数值时,应打开另一个表格并打开。通过以下代码,
string item1,item2;
item1 = listView1.Items [listView1.FocusedItem.Index] .SubItems [ 2 ]。文字;
if (item1.StartsWith( IN ))
{
Stock_Card_Drill_Form scds = new Stock_Card_Drill_Form( Stock_IN, ,< span class =code-string> );
scds.Show();
}
if (item1.StartsWith( OU))
{
Stock_Card_Drill_Form scdo = new Stock_Card_Drill_Form( Stock_Out, , );
scdo.Show();
}
如果我们加倍,此代码项1中的
将获得IN 123值点击IN 123值...如果条件是如果item1以IN开头,那么特定表格将被打开但是123??
i必须拆分文本IN 123 进入IN,& 123为什么三,因为,文本包含一些空格,我想消除那个空格和文本IN和123应该被分成两个值,以便第二个值123(值可能不同)应该传递到我指定的item2字符串
string item1,item2
以便我可以将拆分值用于其他原因..
所以请帮我拆分文本..
你应该简单地使用拆分
函数,如下例所示:
string [] result = item1.Split( new char [] {' '},StringSplitOptions.RemoveEmptyEntries);
if (result.Length == 2 )
{
item1 =结果[ 0 ];
item2 =结果[ 1 ];
// 此处输入使用数据的代码
// ...
}
else
{
// 管理错误....
}
你好
试试这个< br $>
string sValue = listView1.Items [listView1.FocusedItem.Index] .SubItems [ 2 ]。文字;
string [] arrValue = sValue.Split(' );
string sBeforeSpace = arrValue [ 0 ];
string sAfterSpace = arrValue [ 1 ];
如果你想用空格分割字符串,你可以使用
string [] splitItems = item1.Split('');
你可以使用
Stock_Card_Drill_Form scds = new Stock_Card_Drill_Form(Stock_IN,splitItems [0],splitItems [1]);
注意:最好在使用之前检查阵列的长度,这样你就不会得到它索引超出异常范围
hi,
im having listview items as
COLUMN1
IN 123
OU 234
when i double click on the values, another form should be opened and it was opening. by the following code,
string item1,item2;
item1 = listView1.Items[listView1.FocusedItem.Index].SubItems[2].Text;
if (item1.StartsWith("IN"))
{
Stock_Card_Drill_Form scds = new Stock_Card_Drill_Form("Stock_IN", "", "");
scds.Show();
}
if (item1.StartsWith("OU"))
{
Stock_Card_Drill_Form scdo = new Stock_Card_Drill_Form("Stock_Out", "", "");
scdo.Show();
}
in this code item1 is getting "IN 123" value if we double click on "IN 123" value... and in if condition if item1 starts with IN the specific form will be opened but what about the " 123" ??
i have to split the text"IN 123" into "IN", " " & "123" why three because, the text contain some space, i want to eliminate that space and text IN and 123 should be split into two values so that second value 123(values may differ) should be passed into item2 string which i specied in
string item1, item2
so that i can use the split value for another cause..
so please help me to split the text..
You should simple use theSplit
function like in the next example:
string[] result = item1.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); if(result.Length == 2) { item1 = result[0]; item2 = result[1]; // Put here the code for using the data //... } else { // Manage the error.... }
Hello
Try this
string sValue = listView1.Items[listView1.FocusedItem.Index].SubItems[2].Text; string[] arrValue = sValue.Split(' '); string sBeforeSpace = arrValue[0]; string sAfterSpace = arrValue[1];
If you want to split the string with space, you can use
string[] splitItems = item1.Split(' ');
and you can use
Stock_Card_Drill_Form scds = new Stock_Card_Drill_Form("Stock_IN", splitItems[0] , splitItems[1] );
Note: It is better to check the length of the array before using it, so that you will not get a index out of bound of exception
这篇关于如何在if条件下使用split条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!