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 PatelPosted Aug 6, 2009, 2:33 PM
Here is What you Want and
please mark my post as answer :) it will help me to gain some credit :)
Thank you .
Kirtan PatelPosted Aug 6, 2009, 11:00 AM
Vinni Constructed your Logic :)
vinni jainPosted Aug 10, 2009, 3:58 AM
I need ur help..........
plz can u help me in my Question "inserting values in table" .........
vinni jainPosted Aug 6, 2009, 3:21 PM
Kirtan PatelPosted Aug 6, 2009, 3:10 PM
Happy Coding :)
vinni jainPosted Aug 6, 2009, 3:04 PM
can u plz tell me how to mark it as answer
vinni jainPosted Aug 6, 2009, 2:02 PM
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 jainPosted Aug 6, 2009, 9:35 AM
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...
Kirtan PatelPosted Aug 4, 2009, 9:26 AM
vinni jainPosted Aug 4, 2009, 7:59 AM
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 PatelPosted Aug 4, 2009, 5:54 AM
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 jainPosted Aug 3, 2009, 1:52 PM
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#
Anurag GuptaPosted Aug 2, 2009, 12:57 AM
Kirtan PatelPosted Aug 1, 2009, 2:57 PM
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 :)
EamonnPosted Aug 1, 2009, 2:54 PM