java获取字符串第一个字符,如何获取任何字符串的第一个字符

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).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值