[C#]Basic Problem

11/22/2009 00:18 xxFastBoy#1
[Only registered and activated users can see links. Click Here To Register...]

How to make this?

Character string entered from textbox within the framework of defined rules change below to display a label. Each odd-numbered characters in the string of characters from the character after the change in him. These rules next couple bi the file.

Example: ABCDEFGHIJK -> CBAFEDİHGJK
11/22/2009 00:50 Diabox#2
Quote:
Originally Posted by xxFastBoy View Post
[Only registered and activated users can see links. Click Here To Register...]

How to make this?

Character string entered from textbox within the framework of defined rules change below to display a label. Each odd-numbered characters in the string of characters from the character after the change in him. These rules next couple bi the file.

Example: ABCDEFGHIJK -> CBAFEDİHGJK
I'm not familiair with C# and visual studio but if I understand it correctly, you want a string to change from a certain value to a value which is given as input by the user?

This is how I would do it in java:
So for example:

String myString = "ABCD";
Scanner myScan = new Scanner(System.in);
myString = myScan.nextLine();
11/22/2009 01:25 #*=DarkAngeL=*##3
Is it set to random, cause is same letters?
11/22/2009 01:41 xxFastBoy#4
Quote:
Originally Posted by #*=DarkAngeL=*# View Post
Is it set to random, cause is same letters?
No its Not Randomly

Example

ABCDEFGHIJK -> CBAFEDIHGJK

ABC = CBA - DEF = FED - GHI = IHG - JK = JK


its my homework from School But I Dont Know how To make our teacher Verry Stupid. :S
11/22/2009 01:48 Korvacs#5
Code:
for (int i = 0; i < textBox1.Length; i++)
{
     if(i & 1) //Odd Number
     {
          label1.Text[i] = textBox1.Text[i + 2];
     }
     else //Even Number
     {
          label1.Text[i] = textBox1.Text[i];
     }
}
Something similar to that, ive not tested it, but i think that should do something similar to what you want.
11/22/2009 03:14 xxFastBoy#6
Quote:
Originally Posted by Korvacs View Post
Code:
for (int i = 0; i < textBox1.Length; i++)
{
     if(i & 1) //Odd Number
     {
          label1.Text[i] = textBox1.Text[i + 2];
     }
     else //Even Number
     {
          label1.Text[i] = textBox1.Text[i];
     }
}
Something similar to that, ive not tested it, but i think that should do something similar to what you want.

thanks but i got some errors

in here
Quote:
for (int i = 0; i < textBox1.Length; i++)

"system.windows.forms.textbox. does not contain a definitiation for 'lenght' and no extension method 'lenght' accepting a firs arrgument of type 'system.windows.forms.textbox' could be found (are you missing a using directive or an assembly reference?)"
And

in here
Quote:
if (i & 1)

" cannot implicitly convert type 'int' to 'bool' "
in here
Quote:
label1.Text[i]


Property or indexer 'string.tis[int]' cannot be assigned to -- it is read only
11/22/2009 10:50 ChingChong23#7
do textBox1.Text.Length, if that fails try textBox1.Text.Length() (not sure if Length is a direct variable or method)
11/22/2009 16:58 Diabox#8
Use textBox1.Length, without the semicolon.
Try: if ((i % 2) != 0) // Odd number
11/22/2009 19:07 xxFastBoy#9
Anyone Can tell me Full Codes Cause I dont understand :S
11/22/2009 19:13 Korvacs#10
Quote:
Originally Posted by xxFastBoy View Post
Anyone Can tell me Full Codes Cause I dont understand :S
This is homework right? If thats the case then you should figure it out for yourself, although im alittle confused about why your writing this in C# when you dont really know the language at all.
11/22/2009 19:31 Diabox#11
Ok so here's the deal, you want to swap the characters if the string exists out of an odd number of characters (3), so ABC becomes CBA, and if it's an even number (2), it stays the same AB becomes AB. And if the string contains more than 3 characters, you want it to split it up in as many "3" character strings as you can and swap again, so in case of a 10-character string it needs to chop it in 3 seperate strings of 3 and 1 string of 1 character. Am I correct?

So first you need to check if the string contains either 2 or 3 characters or more. You would want to write a method for it. I'm not known with C# so I'll do it in java.


Code:
/*
 * Method which checks if the string consists out of more than 3 characters
 */
public static boolean moreThanThree(String myString) {
    int strl = myString.length();
    if (strl > 3) {
        return true;
    }
    else {
        return false;
    }
}
Ok now you have to write a method which swaps the contents of the string, I could do this in java, but I think you'll have a hard time converting it to C# since you're new to the language... It would be rather equal to the code which is given earlier.
11/22/2009 19:52 xxFastBoy#12
Quote:
Originally Posted by Korvacs View Post
This is homework right? If thats the case then you should figure it out for yourself, although im alittle confused about why your writing this in C# when you dont really know the language at all.
Ah Sorry its not only This

iam are in a project i think someone help me about my problem