How do I keep the apostrophes when importing csv to sqlite - sql

I am using an SQL database in an android app and have encountered a problem with apostrophes.
My database is a quotes database which I have in MS Excel 2007, then saved in .csv format. I then imported this into the sql table I have for the app. However the quotes with an apostrophe are not displaying correctly in the database (and therefore the app). Each apostrophe is replaced with a character that is invisible. I know it is there because of the character count and the fact that in the word "aren't" for example which looks like "arent" it take 3 clicks of the right arrow to get from the left side of the n to the right side of the t. If I manually add an apostrophe to the sql table it converts back to this invisible character when the database is saved. In the android app this invisible character shows up as a hollow rectangle.
I am sure the issue does not lie in my app's displaying of the quote because I have passed in a String to the same code and it displays apostrophes perfectly fine.
Is there a way to fix this issue, possibly by changing the character set or something like that? or does SQL not support apostrophes?

Since a single quote and apostrophe are the same character you have to do something in sql to tell the database when to treat it as part of a string or when to use it to surround a string. In every RDBMS of which I am aware, if you want the character to be part of a string, you "quote the quote", ie you change ' to '' when talking to your database.
That seems to be only part of your problem. The other part is that your android app displays this character as a rectangle instead or an apostrophe. That's got nothing to do with sql. That is a function of the android application.

I found an alternative solution to the problem.
At runtime of the app I'm replacing the invisible character with an apostrophe and the final string is then how the quote should look.
String quote = (get the quote from the SQL table)
char[] tempQuoteCharArr = new char[quote.length()];
tempQuoteCharArr = quote.toCharArray();
for(int i = 0; i < quote.length(); i++){
if(tempQuoteCharArr[i] == ''){
tempQuoteCharArr[i] = '\'';
}
}
quote = String.valueOf(tempQuoteCharArr);
The invisible character is between the single quotes in the if statement.

Related

How can I disable automatic string detection in VS2015?

I'm using VB.NET, and my code contains a lot of strings that very often have double quotes inside of them. My problem is that as I'm fixing the string to escape double quotes (replacing every '"' with '""' inside of the string) it messes with the proceeding code, temporarily assuming everything is a string (since the double quotes don't match up) and completely messing up the formatting of other strings. It assumes that the start of a following string is the end of the current string which causes the actual string to be interpreted and formatted as code, which I have to go back and fix (since it adds spaces and other formatting characters that shouldn't actually be there).
Is there any way to disable this behavior? I didn't have the same problem in VS2013. I've been looking under Tools > Options > Text Editor > Basic, but I couldn't find anything relevant.
Additional Information: I can just modify the strings in a separate text document to escape all of the double-quotes (which is what I've resorted to for now), but in VS2013 I could easily just copy/paste the strings directly into my code without it messing up proceeding strings by temporarily interpreting them as code due to the uneven count of double-quotes.
This behavior is especially problematic when manually adding double-quotes within strings, because if you don't escape them quickly enough (or make a brief typo when doing so), you get the same issue.
You might notice that for other languages, such as C++, writing a string on one line (even with an uneven number of double-quotes) does not affect proceeding lines. Having this same behavior for VB would be great, assuming that there's some setting to enable it.
Yes its an inconvenience.
What I usually do is put some non-used character (e.g. some unused symbol on keyboard, or Alt+{some number}) instead of double quotes. When I'm done building my string whatever way I want, I just finalize it with either bringing up the Find and Replace box and replace that character with two double-quotes. Or just put a REPLACE statement immediately following it, replacing that character with Chr(34).
Instead use Chr(34), or if you end up repeating strings at all, store them as a resource.

Read a text file and display result in a window

I have a text file which contains about 60 lines. I would like to parse out all the text from that file and display in a window. The text file contains words that are separated by an underscore. I would like to use regular expression to solve this problem.
Update:
This is my code as of now. I am trying to read "filename" in my code.
Dim filename = "D:\databases.txt"
Dim regexpression As String = "/^[^_]*_([^_]*)\w/"
I know I don't have much done here anyway but I am trying to learn VB on my own and have gotten stuck here.
Please feel free to suggest what I should be doing instead.
Something like this:
TextBox1.Lines = IO.File.ReadAllLines("fileName")
To remove underscores:
TextBox1.Lines = IO.File.ReadAllLines("fileName").Replace("_", String.Empty)
If you also need other special characters removed, you can use Regex.Replace:
Remove special characters from a string
Also on MSDN:
How to: Strip Invalid Characters from a String
Or the old school way - loop through all characters, and filter only those you need:
Most efficient way to remove special characters from string

Winforms problem with codepage "?" char instead of apostrophe '

In .NET 3.5, I have a Winform with a combobox in it. The datya comes from a DB2 mainframe DB. The problem is that we have a character that is not the real apostrophe. Pasted from Word I'd guess. But in our combobox, it is not diplayed correctly. It shows a question mark "?" instead.
Any idea on how could I get it to display the character as it is ?
First you should check if the character is intact in the database, or if the problem is that the code page doesn't support the character.
If the code page used in the database doesn't support the character, it has been replaced with a question mark, and the data is lost. The best you could do in that case is to try to figure out which question marks are the result of data loss, and which are supposed to be question marks, and try to recreate the data.
If the character is intact in the database, you should just need to make sure that the font used to display the text supports unicode.
Note: The character used is probably a typographic apostrophe like unicode character U+2019.

How to represent Unicode character in VB.Net String literal?

I know you can put Unicode character codes in a VB.Net string like this:
str = Chr(&H0030) & "More text"
I would like to know how I can put the char code right into the string literal so I can use Unicode symbols from the designer view.
Is this even possible?
Use the ChrW() function to return Unicode characters.
Dim strW As String
strW = ChrW(&H25B2) & "More text"
The C# language supports this with escapes:
var str = "\u0030More text";
But that isn't available in VB.NET. Beware that you almost certainly don't want to use Chr(), that is meant for legacy code that works with the default code page. You'll want ChrW() and pass the Unicode codepoint.
Your specific example is not a problem, &H0030 is the code for "0" so you can simply put it directly in the string literal.
Dim str As String = "0MoreText"
You can use the Charmap.exe utility to copy and paste glyphs that don't have an easy ASCII code.
Replace Chr with Convert.ToChar:
str = Convert.ToChar(&H0030) & "More text"
To display an Unicode character, you can use following statement
ChrW(n) where n is the number representing de Unicode character.
Convert.ToChar(n)
type directly character in editor using Alt + N key combination
paste/copy Unicode character directly in editor
Char.ConvertFromUtf32(n)
XML String using &#x....; syntax
Example to assign ♥ character :
s = ChrW(&H2665)
s = Convert.ToChar(&H2665)
s = "♥" 'in typing Alt+2665
s = "♥" 'using paste/copy of ♥ from another location
s = Char.ConvertFromUtf32(&H2665)
s = <text>I ♥ you</text>
BUT when Unicode Character is greater than 0xFFFF (C syntax is more readable 😉), only method 4, 5 and 6 are working !
ChrW() function indicates an error at build
Convert.ToChar() function crashes at runtime
Alt+N is refused because it accepts only 4 digits
Example
lblCharacter.Text = "This solution works 😉"
Debug.Print (Char.ConvertFromUtf32(&H1F600))
s = <text>diable: 😈</text>
PS: smiley pasted (0x1F600) directly in Visual Studio code editor or Notepad++ have lost background color ! Explanation: the smiley pasted in this answer is filled by orange color but in Visual Studio editor or Notepad++, this color has disappeared !
To use String literals in Visual Studio Editor, you must use method 3 or 4 !
In Form (Design mode)
In Properties (see Text property)
I was hoping you could use XML literals and XML escapes but it doesn't work. I don't think XML literals allow you to use &#NN;. Although it is a way of including quotes " inside strings.
'Does not compile :('
Dim myString = _
<q>This string would contain an escaped character  if it actually compiled.</q>.Value
I use the Character Map utility (charmap.exe). Run and select the characters you want in the control's font, such as ©Missico™, copy then paste into the Text property in the property grid. You will have to change the font because the default font for a form is "Microsoft Sans Serif" which is not a Unicode font. I do not think you can use this method for non-printable characters.
Depending on your needs, you can also use Localization, which creates resource files for each language. Again, you would use charmap.exe to select and copy the characters needed and paste them into the resource file. You probably can use non-printable characters, such as tabs, newline, and so on, since this is just a text file (Unicode).
No, it's not possible since VB strings don't support escape sequences. Simply use ChrW, which is a few characters more to type, but also a bit cleaner.

Displaying a Downward Triangle in VB.NET ▼ (U+25BC)

Hey, I'm trying to figure out how to display the ▼ character properly in a .NET winform application.
I am creating a custom control, and for the button, I want this character to appear. I am able to set the text to this character, but it appears as a blank square.
Any ideas on what I need to do to make this character appear properly on my forms?
I am using Arial font, which is compatible with this symbol.
EDIT: It is currently being set as follows:
btnCalendarToggle.Text = "▼" 'Yes, it appears exactly like this in my code
More information on the character can be found here:
http://www.fileformat.info/info/unicode/char/25bc/index.htm
EDIT2: I tried adding some other Unicode characters, and got the following message:
"Some Unicode Characters in this file
cannot be saved in the current
codepage. Do you want to resave this
file as Unicode in order to Maintain
your data?"
After clicking YES on this message, it still didn't work. It appears that the encoding method may be wrong for the file... I don't know what to set it to. Has anyone else tried to display this character in a winform before?
There can often be issues (both with source control systes and diff tools) if you embed more complex unicode characters in source files.
It is often better to do it via an explicit escape sequence and keep the source file in a simpler encoding.
btnCalendarToggle.Text = "\u25BC";
If this works it is likely that the problem is instead the encoding settings for the source file.
Are you certain however that the font in question is Arial (try debugging and checking) since regardless of the above mentioned issues so long as the encoding is set to a legitimate Unicode one (and Visual Studio will convert the file for you if you embed such a character in it) this should have worked.
Can you post the code you are currently using ?
You can print out characters using the chr(int) function if you know the character code.
Dim i As Integer
For i = 0 To 255
txtTest.Text = txtTest.Text & Chr(i) & " -- " & i.ToString() & Environment.NewLine
Next i
Try that and see if your character prints out.