hello
Is it possible to get character character code in Visual Basic 2008 and to get character from character code ( Without form1_keyDown or KeyUp)?.
What i need is two functions, first to get character code of a character, and second to get character from character code.
thank you.
From Unicode code point (not, strictly speaking, ASCII) to character: Chr and ChrW.
Inverse direction: Asc and AscW.
To get the character representation in specific encodings you need to use the methods of the System.Text.Encoding class.
From MSDN:
Public Function Chr(ByVal CharCode As Integer) As Char
Public Function ChrW(ByVal CharCode As Integer) As Char
Related
I am trying to take a string like "Hello my name is Nick" and transform it to "Hello+my+name+is+Nick" to be passed through a URL. This would be easily done by replacing all the spaces with a + char however I also need to replace all special characters (. , ! &) with their ASCII values. I have searched the net but cannot find anything. I wonder if anyone knows of existing code to do this as its a fairly common task?
I think you're looking for this: HttpUtility.UrlEncode Method (String)
Handles non-URL compliant characters and spaces.
Our application receives data from various sources. Some of these contain HTML character makeup instead of regular characters. So instead of string "â" we receive string "â".
How can we convert "â" to a character in the database character set using SQL/PLSQL?
Our database is 10GR2.
Unescape_reference and excape_reference I believe is what you're looking for
UTL_I18N.UNESCAPE_REFERENCE('hello < å')
This returns 'hello <'||chr(229).
http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/u_i18n.htm#i998992
You can use the CHR() function to convert an ascii character number to a character representation.
SELECT chr(226)
FROM dual;
CHR(226)
--------
â
For more information see: http://www.techonthenet.com/oracle/functions/chr.php
Hope it helps...
one solution
replace(your_test, 'â', chr(226))
but you'd have to nest many replace functions, one for each entity you need to replace. This might be very slow if you have to replace many.
You can wrote your own function, seqrching for the ampersand and replacing when found.
Have you searched the Oracle Supplied Packages manual? I know they have a function that does the opposite for a few entities.
to convert a column in oracle which contains HTML items to plain text, you could use:
trim(regexp_replace(UTL_I18N.unescape_reference(column_name), '<[^>]+>'))
It will replace HTML character as above stated but will also remove HTML tags en remove leading and trailing spaces.
I hope it will help someone.
I need a complete list of characters that should be escaped in sql string parameters to prevent exceptions. I assume that I need to replace all the offending characters with the escaped version before I pass it to my ObjectDataSource filter parameter.
No, the ObjectDataSource will handle all the escaping for you. Any parametrized query will also require no escaping.
As others have pointed out, in 99% of the cases where someone thinks they need to ask this question, they are doing it wrong. Parameterization is the way to go. If you really need to escape yourself, try to find out if your DB access library offers a function for this (for example, MySQL has mysql_real_escape_string).
SQL Books online:
Search for String Literals:
String Literals
A string literal consists of zero or more characters surrounded by quotation marks. If a string contains quotation marks, these must be escaped in order for the expression to parse. Any two-byte character except \x0000 is permitted in a string, because the \x0000 character is the null terminator of a string.
Strings can include other characters that require an escape sequence. The following table lists escape sequences for string literals.
\a
Alert
\b
Backspace
\f
Form feed
\n
New line
\r
Carriage return
\t
Horizontal tab
\v
Vertical tab
\"
Quotation mark
\
Backslash
\xhhhh
Unicode character in hexadecimal notation
Here's a way I used to get rid of apostrophes. You could do the same thing with other offending characters that you run into. (example in VB.Net)
Dim companyFilter = Trim(Me.ddCompany.SelectedValue)
If (Me.ddCompany.SelectedIndex > 0) Then
filterString += String.Format("LegalName like '{0}'", companyFilter.Replace("'", "''"))
End If
Me.objectDataSource.FilterExpression = filterString
Me.displayGrid.DataBind()
I have a Sql statament using special character (ex: ('), (/), (&)) and I don't know how to write them in my VB.NET code. Please help me. Thanks.
Find out the Unicode code point for the character (from http://www.unicode.org) and then use ChrW to convert from the code point to the character. (To put this in another string, use concatenation. I'm somewhat surprised that VB doesn't have an escape sequence, but there we go.)
For example, for the Euro sign (U+20AC) you'd write:
Dim euro as Char = ChrW(&H20AC)
The advantage of this over putting the character directly into source code is that your source code stays "just pure ASCII" - which means you won't have any strange issues with any other program trying to read it, diff it, etc. The disadvantage is that it's harder to see the symbol in the code, of course.
The most common way seems to be to append a character of the form Chr(34)... 34 represents a double quote character. The character codes can be found from the windows program "charmap"... just windows/Run... and type charmap
If you are passing strings to be processed as SQL statement try doubling the characters for example.
"SELECT * FROM MyRecords WHERE MyRecords.MyKeyField = ""With a "" Quote"" "
The '' double works with the other special characters as well.
The ' character can be doubled up to allow it into a string e.g
lSQLSTatement = "Select * from temp where name = 'fred''s'"
Will search for all records where name = fred's
Three points:
1) The example characters you've given are not special characters. They're directly available on your keyboard. Just press the corresponding key.
2) To type characters that don't have a corresponding key on the keyboard, use this:
Alt + (the ASCII code number of the special character)
For example, to type ¿, press Alt and key in 168, which is the ASCII code for that special character.
You can use this method to type a special character in practically any program not just a VB.Net text editor.
3) What you probably looking for is what is called 'escaping' characters in a string. In your SQL query string, just place a \ before each of those characters. That should do.
Chr() is probably the most popular.
ChrW() can be used if you want to generate unicode characters
The ControlChars class contains some special and 'invisible' characters, plus the quote - for example, ControlChars.Quote
How do you determine if a letter is in the range from A-Z or Digit 0-9? We are getting some corrupted data "I_999Š=ÄÖÆaðøñòòñ".
I thought I could use Char.IsLetterOrDigit("Š") to ID the corrupted data from "I_999Š", but unexpectedly this is returning true. I need to trap this, any thoughts?
I can't help but notice that everyone seems to be missing the real issue: your data "corruption" appears to be an obvious character encoding problem. Therefore, no matter what you do with the data, you will be (mis)treating the symptom and ignoring the root cause.
To be specific, you appear to be attempting to interpret the received binary BYTES as ASCII text, when those BYTES were almost-certainly intended to represent text encoded as something-other-than-ASCII.
You should find out what character encoding applies to the string of text that you received. Then you should read that data while applying the appropriate character encoding transformations.
You should read Joel Spolsky's article that emphasizes that "There Ain't No Such Thing As Plain Text."
Well there are two quick options. The first is to use a regular expression the second is to use the Asc() function to determine if the Ascii value is in the range of those allowable characters. I would personally use Asc() for this.
Should just be:
if (Regex.IsMatch(input, "[A-Za-z0-9]"))
{
// do you thang
}
For Each m As Match In Regex.Matches("I_999Š=ÄÖÆaðøñòòñ", "[^A-Z0-9]")
'' Found a bad character
Next
or
For Each c As Char In "I_999Š=ÄÖÆaðøñòòñ"
If Not (c >= "A"c AndAlso c <= "Z"c OrElse c >= "0"c AndAlso c <= "9"c) Then
'' Found a bad character
End If
Next
EDIT:
Is there something wrong with this answer that warrants the two anonymous downvotes? Speak up, and I'll fix it. I notice that I left out a "Then" (fixed now), but I intended this as pseudocode.
The only way to ensure that you are dealing with printable ASCII characters, regardless of the encoding in the program or even in the string in question is to check each character for a legal value between 32 and 126 (127 = Delete -- not actually a 'printable' character).
i.e.
Public Module StringExtensions
<Extension()>
Public Function IsASCII(inString As String, Optional bPrintableOnly As Boolean = True) ' 127 = Delete (non-printing) < 32 = control characters also, non-printing
Dim lowerLimit As Int32 = If(bPrintableOnly, 32, 0)
Dim upperLimit As Int32 = If(bPrintableOnly, 127, 128)
For Each ch In inString.ToCharArray()
If Not Asc(ch) < upperLimit OrElse Asc(ch) < lowerLimit Then
Return False
End If
Next
Return True
End Function
End Module
You could use a regular expression to filter out the bad characters ... (use Regex.IsMatch instead if you only need to detect it)
str = Regex.Replace(str, "[^A-Za-z0-9]","", RegexOptions.None);
Use Asc(char) function. It returns a ANSI Character Code from 0 to 255. Check ANSI Character Codes Chart
Try the following code:
NOT isNumeric(char)