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
Related
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)
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'm trying to convert a string that contains someones name as "Last, First" to "First Last".
This is how I am doing it now:
name = name.Trim
name = name.Substring(name.IndexOf(",") + 1, name.Length) & " " & name.Substring(0, name.IndexOf(",") - 1)
When I do this I get the following error:
ArgumentOutOfRangeException was unhandled
Index and length must refer to a location within the string
Parameter name: length
Can someone explain why I am getting this error and how I should be doing this?
You are getting error on this:
name.Substring(name.IndexOf(",") + 1, name.Length)
name.Length should have subtracted with the length of the string before the comma.
The best way for that is to split the string.
Dim oFullname as string = "Last, First"
Dim oStr() as string = oFullname.split(","c)
oFullname = oStr(1).trim & " " & oStr(0).trim
MsgBox (oFullname)
The second parameter for String.Substring is the length of the substring, not the end position. For this reason, you're always going to go out of bounds if you do str.Substring(n, str.Length) with n > 0 (which would be the whole point of a substring).
You need to subtract name.IndexOf(",") + 1 from name.Length in your first substring. Or just split the string, as the others have suggested.
simply ,you only need to split the string
Dim originalName As String = "Last,First"
Dim parts = name.Split(","C)
Dim name As String = parts(1) & " " & parts(0)
If you're using the Unix command line--like the terminal on a Mac--you can do it like this:
Let's say that you have a file containing your last-comma-space-first type names like this:
Last1, First1
Last2, First2
Last3, First3
OK, now let's save it as last_comma_space_first.txt. At this point you can use this command I came up with for your particular problem:
sed -E 's/([A-Za-z0-9]+), ([A-Za-z0-9]+)/\2 \1/g' last_comma_space_first.txt > first_space_last.txt
--->>> Scroll --->>>
You're done! Now, go check that first_space_last.txt file! ^_^ You should get the following:
First1 Last1
First2 Last2
First3 Last3
Tell your friends... Or don't...
This would work keeping to the posters format.
Name = "Doe,John"
Name = Replace(Name.Substring(Name.IndexOf(","), Name.Length - Name.IndexOf(",")) & " " & Name.Substring(0, Name.IndexOf(",")), ",", "")
Result Name = "John Doe"
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