The data which I am passing through CSV file contain text as - 1 Micron Filter Cartridge 10"-(DNL). I want to escape " in the text.
Create a CSVReader with a RFC4180Parser and that will allow the data you listed above.
The default CSVReader uses a CSVParser and for that you need to use a \ character, unless you set a different escape character, to let the CSVParser know the quote is just another character in the string and not to be acted upon.
Hope that helps.
Scott :)
Related
I am currently trying to correct pronunciation of a word using dictionary called userdct_eng.dct which later will be converted to .dat file using python.
My problem is I don't know how to modify the pronunciation of an input word which enclosed in double quotes (").
this is the example code inside the dictionary:
[Header]
Name=userdct_eng.dct
Description=userdct_eng
Language=ENG
Content=EDCT_CONTENT_BROAD_NARROWS
Representation=EDCT_REPR_SZZ_STRING
[Data]
you // #'jEs#
"you" // #'jEs#
I am trying to modify word you to pronounce as yes. it's work, this string ( you // #'jEs# ) is working.
And in the second string I am trying to modify word "you" (including the double quotes) to pronouncing as yes. but it doesn't, this string ( "you" // #'jEs# ) doesn't work, the voice still pronounce it as you.
my question is: How to deal with double quotation marks word?
thanks.
SOLVED by using backslash (\) before double quote (").
Example:
\"you\" // #'jEs#
I have a .csv file similar to this one:
id,text,value
1,'foo, bar',5
2,'foo',5
3,'foo"bar',4
It uses single quotes for text.
I would like to read it in with fread(). I tried fread('text.csv', quote = "\'"), but I get 'unused argument' error. Is it possible to read the file in somehow? Can I somehow change the default quoting character?
(Using command line tool as sed to change the single quotes to double quotes also does not work as some field contains double quotes as well.)
When I tried to read a csv file using data.table:fread(fn, sep='\t', header=T), it gives an "Unbalanced " observed on this line" error. The data has 3 integer variables and 1 string variable. The strings in the csv file are not enclosed with ", and yes there are some lines that contains " within the string variable and the " characters are not in pairs.
I am wondering is it possible to let fread just ignore the unpaired " in the variable and continue reading data? Thanks.
Here is the sample data(just one record)
N_ID VISIT_DATE REQ_URL REQType
175931 2013-3-8 23:40:30 http://aaa.com/rest/api2.do?api=getSetMobileSession&data={"imei":"60893ZTE-CN13cd","appkey":"android_client","content":"Z0JiRA0qPFtWM3BYVltmcx5MWF9ZS0YLdW1ydXoqPycuJS8idXdlY3R0TGBtU 1
UPDATE: Now implemented in v1.8.11
From NEWS :
fread now accepts quotes (both ' and ") in the middle of fields,
whether the field starts with " or not, rather than the 'unbalanced
quotes' error, #2694. Thanks to baidao for reporting. It was known and
documented at the top of ?fread (text now removed). If a field starts
with " it must end with " (necessary if the field separator itself is in the
field contents). Embedded quotes can be in column names too. Newlines (\n)
still can't be in quoted fields or quoted column names, yet.
Yes as #agstudy said, embedded quotes are a known documented problem not yet implemented since fread is new. Strictly speaking, I suppose these ones aren't embedded because the string in your example doesn't start with a quote, though.
Anyway, I've filed this as a bug report so it doesn't get forgotten. To be done in the next release. Thanks for highlighting.
#2694 : Strings including quotes but not starting with quote in fread
I have a AppSetting in web.config.
<add key="key" value="\n|\r"/>
When i read it by ConfigurationManager.AppSettings["key"] it gives "\\n|\\r".
Why ?
In the debugger, becuase the backslash is a special character used for things like tabs (\t) and line endings (\n), it has to be escaped by the use of another backslash. Hence any text that contains an actual \ will be displayed as \. If you print it out to a file or use it in any other way, you will find your string only contains the one .
This isn't ConfigurationManager doing anything.
The backslash escaping syntax is only recognized inside of string literals by the C# compiler. Since your string is being read from an XML file at runtime, you need to use XML-compatible escaping (character entities) in order include those characters in your string. Thus, your app settings entry should look like the following:
<add key="key" value="&x10;|&x13;"/>
Because 10 and 13 are the hex values for linefeed and carriage return, respectively.
Like cjk said, the extra slash is being inserted by the debugger to indicate that it is seeing a literal slash and not an escape sequence.
I solved the same problem with a string replacement.
Not beautful.. but works!
ConfigurationManager.AppSettings["Key"].Replace("\\n", "\n")
string str = "\n";// means \n
string str1 = #"\n";// means \\n
From the AppSettings, It seems that when you extract the key's value, # is internally wrapped.. It is done by the compiler not runtime.
I created the register form in asp.net. And I want to validate Name. This is not included special characters especially '#' character. I used a regular expression validator. I wrote in ValidationExpression that is ^[A-Za-z0-9.'-_\s]+$. It is OK special characters exact '#' character. How to correct regexp. Please help me.
'-_ means every character between ' and _, which includes a large number of characters.
You should escape the - by writing \-.