Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

hermannfloimayr
New 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)
2 Solutions

Accepted Solutions
mdmukramali
Valued Contributor III

Re: ASCII to char

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

MVP & Luminary
MVP & Luminary

Re: ASCII to char

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

11 Replies
pradosh_thakur
Honored Contributor II

Re: ASCII to char

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.
MVP & Luminary
MVP & Luminary

Re: ASCII to char

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
Valued Contributor III

Re: ASCII to char

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
Honored Contributor II

Re: ASCII to char

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
Valued Contributor III

Re: ASCII to char

Hi Pradosh,

vice versa it's working.

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

Re: ASCII to char

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

Re: ASCII to char

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);

MVP & Luminary
MVP & Luminary

Re: ASCII to char

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

MVP & Luminary
MVP & Luminary

Re: ASCII to char

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