how to set encoding in text file to UTF8 without BOM

hollydonuthollydonut Member Posts: 27
hi all,

i am trying to generate a text file using report, but with encoding set to UTF8 without BOM.
so far i am able to generate the text file but using UTF8 with BOM using adostream.
how to change into UTF8 without BOM?

Comments

  • ProcatProcat Member Posts: 31
    Not sure if it helps you in any way, but I had a similar issue a few months back and ended up making the following function. Do be aware that I haven't accounted for all possible characters, just the ones we would need, so you may have to add a few more.



    Var	Name		DataType	Subtype	Length
    No	InputString	        Text		500
    No	AddBOM		Boolean		
    
    
    I := 1;
    //If AddBOM is true, add it to the start of the string
    IF (AddBOM) AND (InputString[1] <> 'ï') THEN BEGIN
      CHR := 239;
      InputString := INSSTR(InputString, FORMAT(CHR), 1);
      CHR := 187;
      InputString := INSSTR(InputString, FORMAT(CHR), 2);
      CHR := 191;
      InputString := INSSTR(InputString, FORMAT(CHR), 3);
    END;
    
    //Convert character
    WHILE (I <= STRLEN(InputString)) DO BEGIN
      IF (InputString[I] = 'æ') THEN BEGIN
        CHR := 195;
        InputString[I] := CHR;
        CHR := 166;
        InputString := INSSTR(InputString, FORMAT(CHR), I+1);
        I += 1;
      END ELSE IF (InputString[I] = 'ø') THEN BEGIN
        CHR := 195;
        InputString[I] := CHR;
        CHR := 184;
        InputString := INSSTR(InputString, FORMAT(CHR), I+1);
        I += 1;
      END ELSE IF (InputString[I] = 'å') THEN BEGIN
        CHR := 195;
        InputString[I] := CHR;
        CHR := 165;
        InputString := INSSTR(InputString, FORMAT(CHR), I+1);
        I += 1;
      END ELSE IF (InputString[I] = 'Æ') THEN BEGIN
        CHR := 195;
        InputString[I] := CHR;
        CHR := 134;
        InputString := INSSTR(InputString, FORMAT(CHR), I+1);
        I += 1;
      END ELSE IF (InputString[I] = 'Ø') THEN BEGIN
        CHR := 195;
        InputString[I] := CHR;
        CHR := 152;
        InputString := INSSTR(InputString, FORMAT(CHR), I+1);
        I += 1;
      END ELSE IF (InputString[I] = 'Å') THEN BEGIN
        CHR := 195;
        InputString[I] := CHR;
        CHR := 133;
        InputString := INSSTR(InputString, FORMAT(CHR), I+1);
        I += 1;
      END ELSE IF (InputString[I] = 'à') THEN BEGIN
        CHR := 195;
        InputString[I] := CHR;
        CHR := 160;
        InputString := INSSTR(InputString, FORMAT(CHR), I+1);
        I += 1;
      END ELSE IF (InputString[I] = 'á') THEN BEGIN
        CHR := 195;
        InputString[I] := CHR;
        CHR := 161;
        InputString := INSSTR(InputString, FORMAT(CHR), I+1);
        I += 1;
      END ELSE IF (InputString[I] = 'è') THEN BEGIN
        CHR := 195;
        InputString[I] := CHR;
        CHR := 168;
        InputString := INSSTR(InputString, FORMAT(CHR), I+1);
        I += 1;
      END ELSE IF (InputString[I] = 'é') THEN BEGIN
        CHR := 195;
        InputString[I] := CHR;
        CHR := 169;
        InputString := INSSTR(InputString, FORMAT(CHR), I+1);
        I += 1;
      END;
      I += 1;
    END;
    EXIT(InputString);
    
  • hollydonuthollydonut Member Posts: 27
    thank you for the answer, but my customer has decided to change the encoding.
Sign In or Register to comment.