Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Carriage return characters within string variable in txt format

    Dear statalister,

    I have a weird problem while insheeting data from a txt file. For some reason, one of the string variable contains a CR (carriage return) characters that makes the line breaks and mess up my import. At the end of each observation, there is a CR and LF character.

    first line: Exclusion de cours;;15/09/2014;Dissipation, cr
    Manque de respect caractérisé; cr lf
    second line: Recopier le cours p. 16 et 17, le savoir faire p. 18 et 19: 1, 2, 3. cr lf

    If I simply insheet this txt file the first observation is diplayed in two lines.

    One way I found to deal with the problem is to remove all cr from the txt file using filefilter:
    filefilter "EXP.txt" "EXP_clean.txt", from(\r) to("")

    It works fine but since I am going to use this problem in thousands of txt file I am affraid it is going to mess up others by removing all cr.

    Have you ever experienced something like that?

    Thanks so much

    Adrien



  • #2
    Adrien,
    you can use an intermediate substitute to avoid the problem.

    Click image for larger version

Name:	1096702.png
Views:	1
Size:	4.3 KB
ID:	1097331


    Best, Sergiy Radyakin
    Last edited by Sergiy Radyakin; 19 Mar 2015, 09:32.

    Comment


    • #3
      I'd also note, per an earlier post of mine , that -fileread-() and -filewrite()- can be nicer than -filefilter- for a purpose like this. The approach is the same as Sergiy's, but -subinstr()- is used to clean up a strL that contains the whole file that
      needs cleaning.

      Regards, Mike

      Comment

      Working...
      X