Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
I would like to retrieve data who is stored in file.dat and fill every byte in a array.
In this file.dat file there are numbers. before each number there is a data.
for example
è(26+# 1280 (555(- 1281

so i want to store the data in my array like this
myarray[0]="0"
myarray[1]="8"
myarray[2]="2"
myarray[3]="1"
myarray[4]=" "
myarray[5]="#"
myarray[6]="+"
...
....

i work with visaul studio 2008 smart device c#

i have no idea, please helpe
Thanks

What I have tried:

Hello,
I would like to retrieve data who is stored in file.dat and fill every byte in a array.
In this file.dat file there are numbers. before each number there is a data.
for example
è(26+# 1280 (555(- 1281

so i want to store the data in my array like this
myarray[0]="0"
myarray[1]="8"
myarray[2]="2"
myarray[3]="1"
myarray[4]=" "
myarray[5]="#"
myarray[6]="+"
...
....
Posted
Updated 8-Jun-16 4:55am
v2
Comments
VR Karthikeyan 8-Jun-16 6:49am    
do you wants to store the number or data or both in array?
Jammes_Ca 8-Jun-16 7:26am    
Hello, i want to store the number and the data in the array
thanks
Richard MacCutchan 8-Jun-16 6:49am    
You need to parse the data to extract the portions you are interested in. If the data always follows some pattern then it should not be too difficult.
Jammes_Ca 8-Jun-16 7:27am    
Hello, i want to store the number and the data in the array. how i didn't understand
TheFoZ 8-Jun-16 7:55am    
have you tried just reading the file into a string?

strings are a type of array so you can access any index of a string using myString[x]

1 solution

The easiest way is to start with a Regex. Assuming that the data is always in the form
<prefix bit><space><number you want>
Then the first task is to extract them as separate "codes":
C#
public static Regex regex = new Regex(
      "[^\\s]+\\s\\d+(\\s|$)",
    RegexOptions.Multiline
    | RegexOptions.Compiled
    );
Should do it.
Then use the regex on the file content:
C#
string dataFromFile = File.ReadAllText(path);
MatchCollection matches = regex.Matches(dataFromFile);
if (ms.Count > 0)
    {
    foreach (Match m in matches)
        {
        string code = m.Value.Trim();
        char[] reversed = code.Reverse().ToArray();
        ...
        }
    }
 
Share this answer
 
Comments
Jammes_Ca 8-Jun-16 8:50am    
thanks for the answer, but the big problem is the ReadAllText it's not for compact framwork, this function does't exist on compact framwork :( i did'nt find a way to replace ReadAllText with other function
OriginalGriff 8-Jun-16 8:59am    
Then don't use it!
Come on - I assumed the hard part for you would be working out the regex, not reading text from a file! :laugh:
Jammes_Ca 8-Jun-16 9:02am    
i did this to read the file
string line;
StreamReader file = new StreamReader(@"\Folder\data.txt");
{
line = file.ReadLine();
textBox1.Text = line;
}
in my textbox i got all the data and how do i convert every char to hexa ???
OriginalGriff 8-Jun-16 9:26am    
Put "line" into the code I showed above instead of "dataFromFile", and it'll split out and reverse the characters. After that ... I have no idea what you are supposed to do with it ;)
Jammes_Ca 8-Jun-16 9:50am    
thanks, i have another question. my textbox contain this data (''1#'744 "2036 5 42""
how do i do to splite my textbox from 2036 until 1, i wan tjust to keep this 1#'744 "20362
or from 2036 and the 15 elements before this number2036

thanks

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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