HI!!!!!!!!!
How can I find the index of same digit which is at diffrent postion in any given number(number can be of any length)....
Like we have any number, suppose, 982625
How can we find the index of two 2s in this number.........
I have made a form in which there are two textboxes.In first ,i am entering number(which is 982625) and in second one I am entering the digit(i.e. 2)...
Can anyone provide me C# code for finding index values.............
Loading

Kirtan PatelRank #292 · 8.6K reputationPosted Aug 6, 2009, 7:00 AM EDT
Vinni Constructed your Logic :)
private void button1_Click(object sender, EventArgs e) { char[] CharArray = textBox1.Text.ToCharArray(); char n = Convert.ToChar(textBox2.Text.Trim()); double Final=0; int crev=0; for (int i = CharArray.Length - 1; i >= 0; i--) { int num = Convert.ToInt32(textBox2.Text.Trim()); if (CharArray[i] == n) { Final = Final + num * (Math.Pow(10,crev)); } crev++; } MessageBox.Show("Answer is := " + Final); } Dont Forget to mark it as Answer Please :)Kirtan PatelRank #292 · 8.6K reputationPosted Aug 6, 2009, 10:33 AM EDT
Here is What you Want and
please mark my post as answer :) it will help me to gain some credit :)
Thank you .
private void button1_Click(object sender, EventArgs e) { char[] CharArray = textBox1.Text.ToCharArray(); char n = Convert.ToChar(textBox2.Text.Trim()); double Final=0; int crev=0; int reapeat = 0; for (int i = CharArray.Length - 1; i >= 0; i--) { int num = Convert.ToInt32(textBox2.Text.Trim()); if (CharArray[i] == n) { Final = Final + num * (Math.Pow(10,crev)); reapeat++; } crev++; } if (reapeat > 2) { MessageBox.Show("You Cant repeat Specific digit More Then 2 Time"); } else { MessageBox.Show("Answer is := " + Final); } }Eamonn22 reputationPosted Aug 1, 2009, 10:54 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 1, 2009, 10:57 AM EDT
string s = textBox1.Text;
char[] chararray = s.ToCharArray();
for (int i = 0; i<= s.Length-1; i++)
{
if (chararray[i] == 'a')
{
listBox1.Items.Add(i);
}
}
Happy coding :)
Anurag Gupta22 reputationPosted Aug 1, 2009, 8:57 PM EDT
vinni jain109 reputationPosted Aug 3, 2009, 9:52 AM EDT
for finding placevalue I have made a function ,but can't use it with the function which u provided ....
How can I amke such application in C#
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 4, 2009, 1:54 AM EDT
string s = textBox1.Text;int total = 0;
char[] chararray = s.ToCharArray();
for (int i = 0; i <= s.Length - 1; i++)
{
if (chararray[i] == '2')
{
total = total + int.Parse(chararray[i].ToString());
}
}
MessageBox.Show("Total is := " + total);
vinni jain109 reputationPosted Aug 4, 2009, 3:59 AM EDT
The code which I am using for placevalue is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PV
{
public partial class Form1 : Form
{
string aa;
string co1;
int a;
int c;
int i;
int di;
int f;
int d1;
public Form1()
{
InitializeComponent();
}
void retfirst(string x)
{
int o;
aa = this.textBox1.Text;
o = aa.IndexOf(x);
a = Convert.ToInt32(o);
}
public void aaaa()
{
retfirst(this.textBox2.Text);
c = (aa.Length) - 1;
co1 = "1";
i = (c - a);
while (i > 0)
{
co1 = (co1 + "0");
i = (i - 1);
}
di = int.Parse(co1);
f = int.Parse(this.textBox2.Text);
d1 = (f * di);
}
private void button1_Click(object sender, EventArgs e)
{
aaaa();
this.textBox3.Text = d1.ToString();
this.textBox3.Enabled = true;
}
Now the problem is that I could not integrate ur and mine code together,because here I have to find palcevalue of single digit in a number but when I apply loop (which u gave me),in that case how will I apply code for placevalue for occurence of same digit second time .....
Can u please help me in joining codes together for finding placevalue of any digit which is occuring twice in a number...
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 4, 2009, 5:26 AM EDT
vinni jain109 reputationPosted Aug 6, 2009, 5:35 AM EDT
On button click I want the answer to be (2*1000)+(2*10)=2000+20=2020...
I tried to make code for this logic but i think its incorrect ,also its giving errors...
vinni jain109 reputationPosted Aug 6, 2009, 10:02 AM EDT
Can U tell me one more thing...As I am making codes I am testing it for all possible values...In some cases I want to handle exceptions and display error message.....Like ,In above code which u gave me, I want that If user repeates any digit more than twice then computer should display error message as "Enter correct number"..........Like this how can I display error messages in other codes too.
vinni jain109 reputationPosted Aug 6, 2009, 11:04 AM EDT
can u plz tell me how to mark it as answer
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 6, 2009, 11:10 AM EDT
//Function to Check if character is Present More than Twise public bool checkReapeat(char c,string str) { int reapatcount = 0; int i= 0; bool isReapeat = true; Char[] CharArray = str.ToCharArray(); for (i = 0; i if (CharArray[i] == c) { reapatcount++; } } if (reapatcount false; } else { isReapeat = true; } return isReapeat; } // Use the Above function and Do our Workprivate void button1_Click(object sender, EventArgs e) { char[] CharArray = textBox1.Text.ToCharArray(); bool ReapeatisThere = true; //Scanning for Reapeated Digits foreach (char charac in CharArray) { ReapeatisThere = checkReapeat(charac,textBox1.Text.Trim()); if(ReapeatisThere == true) { break; } } //Proceed Further if No Reapeted Digits Found if ( ReapeatisThere == false ) { char n = Convert.ToChar(textBox2.Text.Trim()); double Final=0; int crev=0; int reapeat = 0; for (int i = CharArray.Length - 1; i >= 0; i--) { int num = Convert.ToInt32(textBox2.Text.Trim()); if (CharArray[i] == n) { Final = Final + num * (Math.Pow(10,crev)); reapeat++; } crev++; } MessageBox.Show("Answer is := " + Final); } else { MessageBox.Show("Repeated Digits Found in Number !!"); } }vinni jain109 reputationPosted Aug 6, 2009, 11:21 AM EDT
vinni jain109 reputationPosted Aug 9, 2009, 11:58 PM EDT
I need ur help..........
plz can u help me in my Question "inserting values in table" .........