Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
hermannfloimayr
Contributor
Contributor

ASCII to char

can I covert ASCII code from a table to char in QLIK Sense?

Example:

ASCII Code: 116101115116     should convert to "test".

 

 

 

Labels (1)
  • ASCII

2 Solutions

Accepted Solutions
mdmukramali
Specialist III
Specialist III

Hi,

Maybe can you try something like below.

CharMap:
Mapping LOAD
RecNo() - 1 AS Asciicode,
Chr(RecNo() - 1) AS Char
AutoGenerate 256;

Data:
LOAD *,
MapSubString('CharMap', Num) as formattedText
Inline
[
Num
116101115116
]
;

Thanks,
Mohammed Mukram

View solution in original post

marcus_sommer

Your mapping-table is wrong because you used chr() for both the lookup and the return value. It should look like:

Mapping LOAD
    RecNo() - 1 AS Asciicode, Chr(RecNo() - 1) AS Char
AutoGenerate 256;

- Marcus

View solution in original post

12 Replies
pradosh_thakur
Master II
Master II

Do you have any separator like 116,101,115,116 because ascii starts from 0 and ends at 127 and can be extended. Or if your text jsut carries text the also conversion is possible else ambiguity may arise.
Learning never stops.
marcus_sommer

In general it's possible but without some further data/information like a delimiter between the numbers it could be quite difficult because the chars could have two or three digits and you would need multiple loops to approach the approximately string/value.

- Marcus

mdmukramali
Specialist III
Specialist III

Hi,

Maybe can you try something like below.

CharMap:
Mapping LOAD
RecNo() - 1 AS Asciicode,
Chr(RecNo() - 1) AS Char
AutoGenerate 256;

Data:
LOAD *,
MapSubString('CharMap', Num) as formattedText
Inline
[
Num
116101115116
]
;

Thanks,
Mohammed Mukram

pradosh_thakur
Master II
Master II

Hi Mohammed

Does the above code changes text to asci or the vice versa as well?

I have seen similar code from Jagan which seems to be doing the opposite of what the op is asking
https://community.qlik.com/t5/QlikView-Documents/Replace-characters-with-Ascii-numbers-in-a-string/t...
Learning never stops.
mdmukramali
Specialist III
Specialist III

Hi Pradosh,

vice versa it's working.

I have tested some number combinations and it's giving correct results.
pradosh_thakur
Master II
Master II

It does work. Great stuff.
Learning never stops.
hermannfloimayr
Contributor
Contributor
Author

Hi

I use now this code, but I get no char back. (the [Name] is the row with the ASCII Code.

Tabelle1]:
LOAD
    [ID],
    [Name],
    [Preis]
 FROM [lib://Mist/ascii.xlsx]
(ooxml, embedded labels, table is Tabelle1);

CharMap:

Mapping LOAD

Chr(RecNo() - 1) AS Asciicode,

Chr(RecNo() - 1) AS Char
AutoGenerate 256;


DATA:
LOAD [Name],
    
MapSubString('CharMap', Name) as formattedText
    
 FROM [lib://Mist/ascii.xlsx]
(ooxml, embedded labels, table is Tabelle1);

marcus_sommer

The below suggested mapsubstring-approach is surely a good starting-point but if your ASCII didn't contain just simple string-values else line-breaks, (multiple) spaces, tabs or other special chars you might not get the expected results. Therefore you should look for a delimiter and maybe there is already one not visible within the ASCII (a check with notepad++ would be useful) or this information exists within another field.

- Marcus

marcus_sommer

Your mapping-table is wrong because you used chr() for both the lookup and the return value. It should look like:

Mapping LOAD
    RecNo() - 1 AS Asciicode, Chr(RecNo() - 1) AS Char
AutoGenerate 256;

- Marcus