Hi friends,
I have a problem, suppose I enter a number say 123456 then it will give an output as 12-34-56 . How can this possible, Is their any inbuilt function for this is c# language?
Perform function on numbers?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


FroglegRank #1,020 · 1.9K reputationPosted Sep 21, 2012, 12:44 AM EDT
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox1.Text))
{
return;
}
string ss = textBox1.Text;
textBox2.Text = StringExtensions.MultiInsert(ss, "-", 1, 3);
}
}
}
public static class StringExtensions
{
public static string MultiInsert(string str, string insertChar, params int[] positions)
{
StringBuilder sb = new StringBuilder(str.Length + (positions.Length * insertChar.Length));
var posLookup = new HashSet
for (int i = 0; i < str.Length; i++)
{
sb.Append(str[i]);
if (posLookup.Contains(i))
sb.Append(insertChar);
}
return sb.ToString();
}
VulpesRank #55 · 29.2K reputationPosted Sep 21, 2012, 1:00 AM EDT