Hi everybody, I know this is going to sound like and easy to answer question, and probably it is, but I need to split a string that have no delimiters, either by determined sizes (about five different sizes) or only by 8 bits each, and then manipulate the string from there. the values I am getting are '1' and '0' but no commas, headers or spaces or any other delimiter for the string.
The actual string can be between 800 bits to 14000 bits long. No spaces and some of these values are text, other are numbers and other dates.As soon as I split the string I can manipulate it individually.
I have looked in many places for the answer but everything point to delimiters, I haven't found one with my situation in particular. If you can point me to the right place would be great.
By the way the string comes from a socket connection and after I manipulate it I have to put it in a Database and then move the file to let another to come through.
Thanks in advance for your help
Loading
AlexPosted Aug 19, 2008, 7:19 PM
string s = "10001010001010010101010011111011101010101"; ??
You're saying that these are bit values, and you want to split them by each eight characters? If so, that can be done in a few ways, I'll show you one way.
List
int i = 0;
for (i = 0; i + 8 < s.Length; i += 8)
{
values.Add(s.Substring(i,8));
}
values.Add(s.Substring(i,s.Length - i));
L APosted Aug 20, 2008, 9:18 AM
Yes that is exactly what I need, the string will look as:
"10001010001010010101010011111011101010101"; (but is going to be huge)
Your procedure works great, it splits the values every eight values and put them in a list.
After I have it in a list I can put them in a foreach loop to make a CSV file?, I don't know if this is the best approach to my problem, since when I was searching I found that if I want to insert this values in SQL Server maybe it is better to do it directly from the raw Data than doing all the work to save it as CSV, and then read this file to put it in SQL Server.
My point here is which way is best
-Raw Data manipulated and tirmmed to be put in SQL
-CSV File read to Dataset and insert it to SQL
If you can point me in the best direction I will keep looking for that way instead of being wandering and getting frustrated with this.
I appreciate your answer very much
Regards
L