I have an Arabic expression decoded using base64 and should be encoded in a function using vb.net, then filled in a dataset to be displayed in crystal report.
Now the main problem is the below:
The retrieved data is decoded in base64 but I am not able to encoded and display it in Arabic properly. I have used 3 ways, but all of them are not displaying characters properly; If I take the expression and paste in an online converter, it will converted properly (so without doubts the expression was decoded correctly).
Dim test = "2YbYtSDZgdmKINin2YTZhNi62Kkg2KfZhNi52LHYqNmK2Kk="
Dim data = System.Convert.FromBase64String(test)
Dim endodedData = System.Text.ASCIIEncoding.ASCII.GetString(data)
returns: ???? ???? ?????????? ??????????????
Dim win= Encoding.GetEncoding("windows-1256")
Dim endodedData2 = win.GetString(data)
returns: ظ†طµ ظپظٹ ط§ظ„ظ„ط؛ط© ط§ظ„ط¹ط±ط¨ظٹط©
Dim iso = Encoding.GetEncoding("ISO-8859-6")
Dim endodedData3 = iso .GetString(data)
returns:
ع" & ChrW(134) & "ظ ع" & ChrW(129) & "ع" & ChrW(138) & " ظع" & ChrW(132) & "ع" & ChrW(132) & "ظظ ظع" & ChrW(132) & "ظظظع" & ChrW(138) & "ظ
The expected expression that should be returned should be :
نص في اللغة العربية
Any help?
Ok I got it :
Dim endodedData4 = Encoding.UTF8.GetString(data)
Related
When using Strings.StrConv to convert simplified chinese to traditional chinese, it returns some word(s) as a "?".
Dim input as String = "简体中文";
Dim output as String = Strings.StrConv(input, VbStrConv.TraditionalChinese);
messageBox.show("input[" & input & "] output[" & output & "]")
Expected result:
input[简体中文] output[簡體中文]
Got result:
input[简体中文] output[?體中文]
I only get this problem on convering simplified chinese to traditional chinese, but without problem vise versa.
Could someone help if you know how to fix this?
Finally, I solved it by putting Simplified Chinese Locale ID to the 3rd parameter of StrConv!
Dim input as String = "简体中文";
Dim output as String = Strings.StrConv(input, VbStrConv.TraditionalChinese, 2052);
messageBox.show("input[" & input & "] output[" & output & "]")
Got result correctly: input[简体中文] output[簡體中文]
LocaleID from Microsoft: https://msdn.microsoft.com/en-us/library/ms912047(WinEmbedded.10).aspx
I have a function which finds a string between to given strings. Here is an example:
midReturn("?sender=", "&to=", mailItem.HTMLBody)
The above should get the string between ?sender and &to but the & is converted to &.
Is there a way i can look for both occurrences? I did a statement to check this but it doesn't work:
Dim from = midReturn("?sender=", "&to=", mailItem.HTMLBody)
If from < 1 Then
from = midReturn("?sender=", "&to=", mailItem.HTMLBody)
End If
I'm making a program that draws text from a spreadsheet and then pastes it into a .txt file. The problem I've found is that if the character isn't a valid ASCII one it's replaced by characters ranging from ? to ^ or superscript numbers.
I know this is because these characters aren't ASCII supported, but how could I check and swap them out? Is there a list of non-ascii supported characters I can use, or a function that checks validity?
Thanks
ASCII characters have values from 0 to 127, so you could use the AscW function:
If AscW(inputChar) > 127 then
outputChar = "*"c
Else
outputChar = inputChar
End If
' now write outputChar
its' more the other way around. there is no such thing like ASCII support. What you could do is give your textfile a UTF32-BOM first, then your texteditor can interpret the numbers it reads and has the possibility to show the right characters.
see wikipedia "Byte Order Mark".
Edit after discussion:
if you only need 7-bit ASCII and nothing else, use either Encoding.ASCII or Andrews approach.
otherwise you could use ASCIIEncoding.GetEncoding(yourcodepage)
Dim thisText As String = "ÄÖÜäöü" & " Pi: " & ChrW(&H3A0) & " Sigma: " & ChrW(&H3A3)
Dim fileOut As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim enc_ascii As System.Text.Encoding
enc_ascii = System.Text.Encoding.ASCII '7-bit
Using output As New StreamWriter(New FileStream(fileOut & "\test1.txt", FileMode.Create), enc_ascii)
output.Write(thisText)
End Using
enc_ascii = System.Text.ASCIIEncoding.GetEncoding(1250) 'central europe
Using output As New StreamWriter(New FileStream(fileOut & "\test2.txt", FileMode.Create), enc_ascii)
output.Write(thisText)
End Using
enc_ascii = System.Text.ASCIIEncoding.GetEncoding(1253) 'greek
Using output As New StreamWriter(New FileStream(fileOut & "\test3.txt", FileMode.Create), enc_ascii)
output.Write(thisText)
End Using
I have a strange problem here. In my code, variable b string, has the value "Test Test Test". This value we can see while debugging the variable as well as in the text visualizer.
Now the problem is, if I show the same string using Messagebox, the value is just "Test". What can I do here to get the complete value.
I am converting from an ebcdic encoded bytes to corresponding utf8 string and doing the above operation. Any thoughts. below is my sample code.
Dim hex As String = "e385a2a300000000e385a2a3000000e385a2a3"
Dim raw As Byte() = New Byte((hex.Length / 2) - 1) {}
Dim i As Integer
For i = 0 To raw.Length - 1
raw(i) = Convert.ToByte(hex.Substring((i * 2), 2), &H10)
Next i
Dim w As String = System.Text.Encoding.GetEncoding(37).GetString(raw)
Dim raw1 As Byte() = Encoding.UTF8.GetBytes(w)
Dim b As String = Encoding.UTF8.GetString(raw1)
MessageBox.Show(b)
Look at the byte array. You have 4 ASCII 0's after each "Test". ASCII character code 0 corresponds to nul, which is a string termination sequence. If you want spaces instead of nulls there...
Dim b As String = Encoding.UTF8.GetString(raw1).Replace(Chr(0), " ")
It is possible that the string "b" might contains some control character.
To test a control char in string.
For Each p As Char In b
MsgBox(p & " " & Char.IsControl(p) & " " & AscW(p))
Next
Use String#Replace to replace control chars.
b = b.Replace(ChrW(0), " ")
MsgBox(b)
I have a string of text i captured within AutoCAD (0.000000, 0.000000, 0.000000) wich is saved to a text based file named position.txt.
as you probably have gatherd with a file name such as position.txt the text could be composed of any random number combination eg: (5.745379, 0.846290, 150.6459046).
However for it to be of any use to me I need the captured string to exist without spaces or brackets how can i achiev this in VB.net?
Use String.Replace. Its probably not the most efficient way but it will get the job done.
Dim file as String = My.Computer.FileSystem.ReadAllText("position.txt")
Dim output as String = file.Replace(" ", "") _
.Replace("(", "") _
.Replace(")", "")
My.Computer.FileSystem.WriteAllText("output.txt", output, false)
as above
s = "(5.745379, 0.846290, 150.6459046)"
s = s.replace("(","")
s = s.replace(")","")
and then
dim answer() as string = s.split(",")
dim number as double
For each a as string in answer
if double.tryparse(a,n) then
console.writeline(n.tostring & " is a number")
else
console.writeline(n.tostring & " is rubbish")
next