I have a number like 6348725, displayed as String, but I want to display only the last 6 digits (348725) with String.Format. Is there a way to do this? I know, there is the Substring Function (or Int calculation with % (Mod in VB)), but I want to use a FormatString by a User Input from a TextBox.
I don't understand why you need String.Format
but you can use it like;
string s = "6348725";
TextBox1.Text = s.Substring(s.Length - 6)); // Textbox will be 348725
Okey, I just wanna show a dirty way without Substring
;
string s = "6348725";
var array = new List<char>();
if (s.Length > 6)
{
for (int i = s.Length - 6; i < s.Length; i++)
{
array.Add(s[i]);
}
}
Console.WriteLine(string.Join("", array)); // 348725
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