Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a C# code to get a value from the registry (the value that is read from the registry includes commas e.g. 12,32,156).

I would like to store 12 in a variable with integer X, and the second variable Y to store the 32 value, finally 156 to be stored inside the Z integer variable.

What I did so far is this:


C#
string Get = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Software\KeyName\KeyName2\KeyName3", "ObjectBts", "").ToString();
MessageBox.Show(Get);
Get.ToCharArray();
int i = 0;

while (Get[i] != '\0')
{
    if (Get[i] == ',')
    {
        i++;
        X += Get[i];
//I would like to get the other value that is after the first comma to be stored in Y (which has to be 32

// Also I would like the third value to be stored in the Z integer (which has to be 156)
    }
    else
    {
        i++;
    }
}
Posted
Updated 28-Jun-14 0:41am
v3
Comments
pradiprenushe 28-Jun-14 6:39am    
are you going to declare 26 variable?
[no name] 28-Jun-14 6:43am    
Assume the value was taken from the REGISTRY is "14,26,265", I want to store the value 14 in a declared variable integer called X, then 26 in a declared variable integer called Y, and finally the 256 in a declared variable integer called Z
pradiprenushe 28-Jun-14 6:49am    
How will you decide no of records? as it is dynamic?
[no name] 28-Jun-14 6:53am    
I don't get it
pradiprenushe 28-Jun-14 6:56am    
How will you decide no of variables to use? As you write a,b and z.
Is it fixed that you are reading only three values?

use the split the function this will stores the value into an array.
var data=Get.Split(',');
int X=Convert.ToInt32(data[0]);
int Y=Convert.ToInt32(data[1]);
int Z=Convert.ToInt32(data[2]);
 
Share this answer
 
Comments
[no name] 28-Jun-14 6:55am    
@R-a-v-i-k-u-m-a-r Thanks! It worked like a charm
C#
var Getstring = str.Split(new [] { ',' }, 2)[0]

2 ensures if there are lots and lots of commas
 
Share this answer
 
Comments
[no name] 28-Jun-14 6:51am    
@Balav4 Your code works but it does not display all the values after the first comma

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900