04-14-2016 11:27 PM - edited 04-14-2016 11:28 PM
I have a notepad in which there are 100s of line and each ending by CR and LF character. I need to insert each record to an array. I tried but this is time cosuming
Text is like
$GPRMC,120442.000,A,1257.4713,N,07744.6606,E,0.00,84.48,211115,,,A*5E<CR><LF>
$GPRMC,120442.000,A,1457.4713,N,07744.6606,E,0.00,84.48,211115,,,A*58<CR><LF>
$GPRMC,120442.000,A,1457.4713,N,07744.6606,E,0.00,84.48,211115,,,A*58<CR><LF>
$GPRMC,120442.000,A,1457.4713,N,07744.6606,E,0.00,84.48,211115,,,A*58<CR><LF>
$GPRMC,120442.000,A,1257.4713,N,07744.6606,E,0.00,84.48,211115,,,A*5E<CR><LF>
$GPRMC,120442.000,A,1257.4713,N,07744.6606,E,0.00,84.48,211115,,,A*58<CR><LF>
Each row I need to insert to an array
Attached text file.
Solved! Go to Solution.
04-14-2016 11:48 PM
04-15-2016 12:18 AM - edited 04-15-2016 12:19 AM
@Ranjeet_Singh wrote:I need to insert each record to an array.
What is a "record"? If each line is a record, use "read from text file" and configure it to "read lines" (right-click...)
04-15-2016 12:39 AM
I used string search, for loop to do this but this is rocking..Thanks
04-15-2016 02:19 AM
With Blokks solution you'll even get the elements extracted.
/Y
04-15-2016 02:48 AM
@Yamaeda wrote:With Blokks solution you'll even get the elements extracted.
/Y
Yes, but that wasn't the question. 😉
04-15-2016 03:07 AM
@altenbach wrote:
@Yamaeda wrote:With Blokks solution you'll even get the elements extracted.
/Y
Yes, but that wasn't the question. 😉
Well, we do not know what the OP wants to do with those "records". So I can just guess maybe he wants to do some operation on each and whole lines as strings. Otherwise if the OP needs to extract individual elements, he should go with my example, to get the 2D string. After that each columns as 1D string arrays can be indexed out, and transformed into numerical values when needed...
04-15-2016 05:02 AM
@Yamaeda wrote:With Blokks solution you'll even get the elements extracted.
/Y
I need 1D not 2D array
04-15-2016 09:59 AM - edited 04-15-2016 10:02 AM
@Blokk wrote:
@altenbach wrote:
@Yamaeda wrote:With Blokks solution you'll even get the elements extracted.
/Y
Yes, but that wasn't the question. 😉
Well, we do not know what the OP wants to do with those "records". So I can just guess maybe he wants to do some operation on each and whole lines as strings. Otherwise if the OP needs to extract individual elements, he should go with my example, to get the 2D string. After that each columns as 1D string arrays can be indexed out, and transformed into numerical values when needed...
We should focus on he original requirement of "Each row I need to insert to an array". A row is the atomic unit here.
Sill, with a bit of a detour, "read delimited spreadsheet" could be used by selecting transpose, using a eol as delimiter, and getting the first row. Same difference. Still, my original solution is more direct and probably more efficient. Read delimited spreadsheed does a lot more work internally.
However, in this particular case, each line seems to contain an identical number of characters, allowing for the possibility to chop up the file by position without even looking at the content. That might be more efficient than having to search for EOL over and over. Worth considering but I have not tried. Probably not worth the effort for more typical file sizes.