I have string 'name' and want to do substring the last number from this string.
string name = "1100_PF_R_06230_1";
textBox1.Text = (name.Substring(name.Length - 1, 1));
name string changes respectively as file number, so string name becomes.
1100_PF_R_06230_1
1100_PF_R_06230_2
1100_PF_R_06230_3
1100_PF_R_06230_4
1100_PF_R_06230_5
1100_PF_R_06230_6
1100_PF_R_06230_7
1100_PF_R_06230_8
1100_PF_R_06230_9
1100_PF_R_06230_10
when it reaches to 10 the my substring gives me 0 and file starts from 1 again. i want to substing name from last '_' underscore so that i can add number to it.
please help.
You can use Split
method with LINQ Last
:
var result = name.Split('_').Last();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With