I need to get a string from textbox and do some things to it.
for example, if the string is "ABCDEF",
Each character has a specified value that i need to set (how
I want to get each of the letters and multiply their value with some index.
when i try to do so, i get an error about string to char conversion.
how do i extract each letter from the string but still keep the main string
thank you for your help.

Working with string/char
chpe
that's much easier than the method i thought of (checking each char and search for "case").
Guillermo Díaz
What sort of table are we talking about
It seems that you know in advance what the mapping between the original character and what its changed value should be (e.g. 'A' would become 'B' etc).
If that's the case then you can use the Collection classes and the work becomes rather easy. Here's an example:
System.Collections.Generic.Dictionary<char, char> table = new System.Collections.Generic.Dictionary<char, char>();
string test = "ABCDEF";
string modifiedTest;
char[] testAsCharArray;
//Place values in the dictionary --> EXAMPLE ONLY
table.Add('A', 'Z');
table.Add('B', 'M');
table.Add('C', '5');
table.Add('D', '4');
table.Add('E', 'P');
table.Add('F', 'Q');
testAsCharArray = test.ToCharArray();
for (int i = 0; i < testAsCharArray.Length; i++)
{
testAsCharArray[ i] = table[testAsCharArray[ i]];
}
modifiedTest = new string(testAsCharArray);
MessageBox.Show(modifiedTest);
OK, so what's happening is that I use the Dictionary class to store key and value pairs. The "key" will be the original character and the "value" will be the new value for the character. I use the Add() function to place new entries in the Dictionary. Note that the first parameter is the "key" and the second parameter is the "value".
NB. You could use other classes like Hashtable but I prefer the use of the Dictionary class because of the type safety that Generics gives us. Note that when I have declared the Dictionary I have stated that the "key" will be a character and the "value" will be a character:
System.Collections.Generic.Dictionary<char, char>
The first entry after the "<" is the data type of the "key" and the second is the data type of the "value".
I would recommend if you have something like a Load() event handler for your form (if you are making a Windows form) you create the Dictionary object there and populate it with values by using the Add() function as per the above example. I would also suggest making it a global variable so that all required routines can access it.
Now, same sort of stuff as before. Get a character array and iterate through it. The difference is this line:
testAsCharArray[ i] = table[testAsCharArray[ i]];
What this guy does it finds the value in the table that corresponds to the key
testAsCharArray[ i]. This is the way you would assign proper values if you were to use the example I have shown you.
Nothing else there is too interesting.
Hope that helps a bit.
Tomas Floyd
Here's an example that may be what you're after:
string test = "ABCDEF";
string modifiedTest;
char[] testAsCharArray;
int index = 5;
testAsCharArray = test.ToCharArray();
for (int i = 0; i < testAsCharArray.Length; i++)
{
testAsCharArray[ i] = (char)((int)testAsCharArray[ i] * index);
}
modifiedTest = new string(testAsCharArray);
NB. In the above code I have used "[ i]". There should not be a space between the "[" and the "i" but I had to put one in otherwise the forum renderer would consider it as an emoticon. You will need to change this so that there is no space in there....Sorry about that.MessageBox.Show(modifiedTest);
So what's happening in the above is that I have an original string (test) which I then change into an array of characters for easier handling.
The array of characters is then iterated over and each letter is replaced by the original letter value multiplied by some offset. Note the cast to int in the calculation is to get the ASCII value for the character.
The final cast to char is to convert the new value (i.e. original value * offset) from an ASCII value into a character value.
A new string is then formed based on the modified letters in the character array by using the constructor for string that accepts a character array as a parameter. The Message Box is for illustration purposes only.
This was just an example to get you started, in your real code you might want to put other things like error handling if the value from the multiplication by the offset is too large to be an ASCII value. Hopefully this was enough to get you started though.
Hope that helps a bit, but sorry if it doesn't
Shawn Songer
I managed to do the String->Char->String conversions...
I have a char table assigning values for some chars and numbers.
I need to assign each character (30 characters) his specific value (some sort of case !).
How can I check each char I get with the table and accordingly assign the proper value
again, thank you for your time.