hello friend
here is my code...string l = dataGridView1[4, a].Value.ToString();
if (l == "Opening Sauda")
{
trantype11 = "O";
}
else if (l == "Percentage Wise")
{
trantype11 = "P";
}
else if (l == "Transation")
{
trantype11 = "T";
}
if datagrid view cell cantain string like Percentage Wise
than trentype11 sholud set forst charector p
like
i try it but no working(it give last character e but i want p )
string b = dataGridView1[1, a].Value.ToString();
broktype11= b.Substring(1, 1);
解决方案
Don''t use substring, use simply char first = b[0]. If by some strange reason you need a string containing this one char, it would be string oneChar = new string(first, 1). That''s it.
—SA
Try string b = dataGridView1[1, a].Value.ToString();
broktype11= b.Substring(0, 1);
If you want the first character in a string use .Substring(0,1) - not .Substring(1,1).
这篇博客探讨了在处理dataGridView控件中的数据时如何正确提取和处理字符串。文章通过示例代码展示了如何根据dataGridView单元格的值设置变量trantype11和broktype11。博主指出,在获取字符串的第一个字符时,应避免使用Substring方法,推荐使用char类型的索引访问或创建新的单字符字符串。此外,还指出了在处理Substring时的一个常见错误,即使用了错误的索引位置。

被折叠的 条评论
为什么被折叠?



