473,513 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I read and seperate a variable into an array?

110 New Member
I have a form where a user enters 4 separate integers of 1 character and then some math occurs leaving a variable of 4 digits. I am trying to then separate that 4 digit variable int so I have 4 members of the array again, each member consisting of 1 value from the 4 digit number. How do I go about this?
May 8 '11 #1
1 1459
adriancs
122 New Member
Expand|Select|Wrap|Line Numbers
  1. int fourdigit = 1234;
  2. char[] chararray = Convert.ToString(fourdigit).ToCharArray();
  3. int[] intarray = new int[chararray.Length];
  4. List<string> StringList = new List<string>();
  5. int i = 0;
  6. foreach (char c in chararray)
  7. {
  8.     intarray[i] = Convert.ToInt32(Convert.ToString(c));
  9.     StringList.Add(Convert.ToString(c));
  10.     MessageBox.Show("Digit 1 = " + StringList[i]);
  11.     i += 1;
  12. }
May 9 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2943
by: Neil Jarman | last post by:
Hi, I need to create an array with a session variable. According to thebook I'm using, the following should work, but if fails: for each key in request.QueryString if left(key,6) = "cboRun"...
6
15454
by: Brad Britton | last post by:
Just wondering how you would break a string such as first and last name together, into two separate strings or variables, each containing the firstName and lastName. I am a newbie at C# so any help...
7
1471
by: Alan | last post by:
I have a main form frmMain and second form frmMember, I declare a variable at the top of the frmMember as Dim memberStr as String In the main form, Dim MemberForm as frmMember
9
1731
by: portroe | last post by:
by the way, how do you deal with a variable array lenth, for example if the array depends on the number of years 'input' by the user, Dim Years(?) As Integer thanks
5
19015
by: yinglcs | last post by:
Hi, I have a method like this: const A* getMaxArea(const vector<A*>& aList); And in my caller, i have this: A* const a = NULL;
3
3579
by: Kevin O'Brien | last post by:
Hello, Can someone please tell me how to read a text box in to an array? What I have in the text box is a string of 7 words seperated by spaces. I would like to read each word into an array. ...
3
1750
by: walterbyrd | last post by:
I know I can use the file() function to read a file into an array by providing a literal file name between single quotes: $lines = file('literal_file_name'); But, what if I want file() to use...
5
4073
by: farrell.niall | last post by:
Hi, I'm trying to use nested foreach loops to loop through two arrays. Each element in the first array corresponds to another array. The brandcode part of the first array is the same as the name...
3
1464
by: Keriana30 | last post by:
I need to base a variable array using a variable. For example, ReDim pstrDepSSN(pintRecordCount) as string The only way to do this is with the ReDim statement but it doesn't permit me to...
0
1338
by: PauloD | last post by:
public struct Character_Items { public short Armor; public short Helm; public short WeaponL; public short WeaponR; public short Pants; public short Boots; public short Gloves; public short...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.