antai Posted March 23, 2023 Share Posted March 23, 2023 (edited) I get badly formatted text files where there is no new line but there is a "." instead of a new line. Is there a quick solution how to read the file into an array, or do I have to read the file char by char and write it to a new file while replacing "." with a new line? // edit: what is the max number of chars I can read into a string? Is that 2147483647 characters (limit for string) or should I reach some other limits why just reading it into a string and parsing it internally? Edited March 23, 2023 by antai Link to comment Share on other sites More sharing options...
ioa747 Posted March 23, 2023 Share Posted March 23, 2023 (edited) FileReadToArray() here an example Edited March 23, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
AspirinJunkie Posted March 23, 2023 Share Posted March 23, 2023 Since, as mentioned, there are no line breaks, a FileReadToArray will barely help you. If, as described, the dot "." is the separator, then the procedure would be as follows: read the whole file into a string via FileRead(). split into an array via StringSplit() with the "." as separator. Musashi 1 Link to comment Share on other sites More sharing options...
ioa747 Posted March 23, 2023 Share Posted March 23, 2023 30 minutes ago, antai said: or do I have to read the file char by char and write it to a new file while replacing "." with a new line? No need StringReplace($sString, ".", @CRLF) replace all together To testing copy the text in clipboard run this code Local $sString = ClipGet() StringReplace($sString, ".", @CRLF) ClipPut($sString) paste the text I know that I know nothing Link to comment Share on other sites More sharing options...
Musashi Posted March 23, 2023 Share Posted March 23, 2023 Here is an example as the result from a FileRead(), as suggested by @AspirinJunkie : #include <Array.au3> Local $sFileStr = "This is an example of a badly formatted text file. The file does not contain the usual " & _ "sequences for line breaks. That would be CRLF or LF. Instead, the line break is caused " & _ "by a period. In addition, it is possible that the dot is used both as a normal " & _ "punctuation mark, . and as an indicator for the line break. Not a very consistent solution :( ." Local $aArray = StringSplit($sFileStr, '.') _ArrayDisplay($aArray) pixelsearch 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now