Jump to content

Replace a char with a new line


 Share

Recommended Posts

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 by antai
Link to comment
Share on other sites

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

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)

 

Musashi-C64.png

"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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...