1. Vipin Dwivedi
  2. PowerBuilder
  3. Wednesday, 17 April 2024 20:06 PM UTC

Hello Appeon Team,

I need one help!

There is one function in PB PowerScript function CharA() which Extracts the first ASCII character of a string or converts an integer to a char as per the document. So CharA(65) will return Corressponding value 'A'. The same conversion we can do in C# by casting number to Char like (Char)65 which will give you value of Ascii of 65 i.e. A. My problem is when I am using CharA(306) it is giving me value 2 in PowerBuilder but when I use the same in C# (Char)306, it is giving me value as 'IJ'. The Ascii table is also showing me same 'IJ' then how Powerscript CharA(306) is showing me 2? What is the logic behind CharA() and how can I achieve the same in C#?

 

Need your expertise help here.

 

Thanks,

Vipin

David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Thursday, 25 April 2024 15:15 PM UTC
  2. PowerBuilder
  3. # 1

I think in C# you need to be using something like this to get the Ascii values:

System.Text.Encoding.ASCII.GetChars(new byte[]{2});
Comment
There are no comments made yet.
Vipin Dwivedi Accepted Answer Pending Moderation
  1. Thursday, 25 April 2024 13:46 PM UTC
  2. PowerBuilder
  3. # 2

PB is showing 147 based on below table chart. https://everythingfonts.com/ascii/codes/147

Comment
There are no comments made yet.
Vipin Dwivedi Accepted Answer Pending Moderation
  1. Thursday, 25 April 2024 13:36 PM UTC
  2. PowerBuilder
  3. # 3

What about AscA() as this is also working differently in PB vs DOTNET. For example AscA('"') [Special Double quote] gives me 147 but (int)('"') in c# gives me 8220. Asc('"') in Powerbuiler is also giving me 8220. What's the logic behind AscA(). Basically I am trying to convert from PowerBuilder code to C# and looking for help.

 

Thank you for your help!

Comment
  1. John Fauss
  2. Thursday, 25 April 2024 14:57 PM UTC
Why do you keep using ASCII-related PB functions, then wondering why their output does not agree with Unicode values from c#?

If you want Unicode characters and Unicode code points, use Unicode-related functions!

PB internally has used Unicode 16LE encoding (16 bits, 2 bytes per character) to represent string and character data since version 10, which was released in 2004. As I stated before, I don't know .NET, but it appears from the information you have supplied that it also uses Unicode.

If you want the numeric code point of a single Unicode (2-byte) character in PB, use the Asc() function, since this matches what c# gives you. The CharA() and AscA() functions in PB should ONLY be used if you are working with ASCII-encoded data.
  1. Helpful 1
  1. Vipin Dwivedi
  2. Thursday, 25 April 2024 15:04 PM UTC
I am converting existing old PB code to C# and I can't change the existing code as it has some complex logic(algorithm) to encrypt and decrypt our business files.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 17 April 2024 21:07 PM UTC
  2. PowerBuilder
  3. # 4

Hi, Vipin -

ASCII codes are single byte values, which is what PB expects... I'm unsure of the rationalization of what C# does, as that makes no sense to me.

Since 306 decimal in binary is larger than 255 (the largest possible integer value for a single byte), the bit pattern gets truncated. In essence, you get Mod(306,256) = 50, and 50 decimal is the ASCII value of the character "2".

    https://www.asciitable.com/

Best regards, John

Comment
  1. John Fauss
  2. Wednesday, 17 April 2024 21:19 PM UTC
Instead of CharA(306), Use Char(306) to obtain the Unicode character.
  1. Helpful 1
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.