I'm wondering how to include a multi line string like an XML data inside a C string? I need to replace some text (MY_REPLACED_TEXT) inside the XML file.
So I include the xml like this:
char myXMLString =
'<?xml version="1.0" encoding="UTF-8"?>'
' <painting>'
' <img src="madonna.jpg" alt="Foligno Madonna, by Raphael"/>'
' <caption>MY_REPLACED_TEXT'
' <date>1511</date>-<date>1512</date>.</caption>'
'</painting>'
However, this doesnt seem to work (I get
"Expected ; after top level declarator" error
).
I've also tried escaping with \ at the end of the line, instead of the apostrophe ' but still not working (I get
"use of undeclared identifier" error
)
Is there a better way to include a string into a compiled C program? Can I include the XML as a file, which is local to the compiled program and search/replace that?
like this
char *myXMLString =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<painting>"
" <img src=\"madonna.jpg\" alt=\"Foligno Madonna, by Raphael\"/>"
" <caption>MY_REPLACED_TEXT"
" <date>1511</date>-<date>1512</date>.</caption>"
"</painting>";
Related
I have problem on removing all comma from string data in SQLite database.
The program is based on C so I use C API of SQLite as sqlite3_mprintf().
I try to get rows matched with input and it needs to be checked without comma(,).
REPLACE() of SQLite is used as REPLACE(data, ',', '').
Sample code is below.
sqlite3_stmt *main_stmt;
const char* comma = "','";
const char* removeComma = "''"
char *zSQL;
zSQL = sqlite3_mprintf(SELECT * FROM table WHERE (REPLACE(colA||colB, %w, %w) LIKE %%%q%%, comma, removeComma, input);
int result = sqlite3_prepare_v2(database, zSQL, -1, &main_stmt, 0);
I refer the sqlite3 reference.
https://www.sqlite.org/printf.html
Any Substitution Types of SQLite3 reference delete apostrophes from input data.
It makes REPLACE() functions different from what I think.
What I expect is SELECT * FROM table WHERE (REPLACE(colA||colB, ',', '') LIKE %q
by passing ',' and '' as argument of sqlite3_mprintf().
However, result is changed as SELECT * FROM table WHERE (REPLACE(colA||colB, ,, ) LIKE %q
so comma is not removed from data, colA||colB, and result is different from what I expect.
Are there any idea to input comma as first argument of REPLACE() with apostrophes
and blank with apostrophes as second argument?
I get an error where it states invalid column 'DatabaseSQL' when I try to add a database reference into an OUTPUT statement like below:
OUTPUT [DatabaseSQL] +'.dbo.Package' 'TableName', 'PackageID', inserted.PackageId,
Core.updXMLFragment('StatusID', inserted.StatusID, Deleted.StatusID)
INTO #OutputList
If I remove the DatabaseSQL and added it as a string like OUTPUT 'Database.dbo.Package..., then it works fine, but I need the statement to actually recognise the database as well as add it as a string, just outputting it as a string alone isn't good enough. Any ideas?
You could use: DB_NAME():
OUTPUT DB_NAME() + '.dbo.Package', 'TableName', 'PackageID' ...
If you store DB name in variable use:
DECLARE #DatabaseSQL SYSNAME = QUOTENAME('name with space');
OUTPUT #DatabaseSQL + '.dbo.Package', 'TableName', 'PackageID' ...
LiveDemo
Is it possible to use a variable in the assignfile command?
Eg.
f : Textfile ;
sFile : string ; {contains 'MyFile.txt' as content}
...
cFileDir = 'C:\Users\User\Desktop\Data Engine\Data\Country' ;
...
Assignfile(f, cFileDir + '\' + sFile) ;
...
I appreciate your help very much. if it's unclear I'll edit the question to add more details.
Is it possible to use a variable in the AssignFile command?
Yes.
The second parameter of AssignFile has type string.
The expression cFileDir + '\' + sFile has type string.
FWIW, AssignFile is known as a function rather than a command. Getting on top of terminology like this will help you learn the language more effectively.
Okay I am still very new to delphi coding and coding in general. I have researched on splitting strings into an array or list delimited by : or , but in this case I need to do it by a string that is delimited by " ".
Example: "fname","lastname","someplace,state","some business,llc","companyid"
and what I need is the array to be
(item[0] = fname) (item[1] = lastname) (item [2] = someplace,state) (item[3] = some business, llc.) (item[4] = companyid)
So as you can see I cannot read in a line of text using the comma as a delimeter because it would throw everything off.
Is there any way to read in a line of text and split it into an array like the example above??
See documentation for TStrings.CommaText.
Here is an example:
program Project1;
{$APPTYPE CONSOLE}
uses
System.SysUtils,Classes;
var sl: TStringList;
s: String;
begin
sl := TStringList.Create;
try
sl.CommaText := '"fname","lastname","someplace,state","some business,llc","companyid"';
for s in sl do
WriteLn(s);
ReadLn;
finally
sl.Free;
end;
end.
The documentation also says:
Note: CommaText is the same as the DelimitedText property with a delimiter of ',' and a quote character of '"'.
So if using DelimitedText, just make sure QuoteChar is " and the Delimiter is ,.
In visual foxpro, i have a cursor which is the result of a sql query, when i export the content of that cursor to a csv file using the statement :
COPY TO "c:\test.csv" type DELIMITED
all data is messed up, i do not pecify any delimiter so basically foxpro takes the default, which is every column in that cursor. bow when i run the same command to an xls file, and then convert it to a csv file...it works very well:
COPY TO "c:\test.xls" type XL5
anyone has had such issue, any one still using foxpro and doing stuff like those?
Have you tried using TYPE CSV in the COPY TO command?
Personally I never liked the built-in DBF to CSV converters. They always seemed to do things I did not want them to do. So I just wrote my own. Here is some code to get you started.
LOCAL lnFields
SELECT DBF
lnFieldCount = AFIELDS(laFields)
lnHandle = FOPEN("filename.csv", 1)
ASSERT lnHandle > 0 MESSAGE "Unable to create CSV file"
SCAN
lcRow = ""
FOR lnFields = 1 TO lnFieldCount
IF INLIST(laFields[lnFields,2], 'C', 'M')
lcRow = lcRow + IIF(EMPTY(lcRow), "", ",") + '"' + ;
STRTRAN(EVALUATE(laFields[lnFields,1]),'"', '""') + '"'
ELSE
lcRow = lcRow + IIF(EMPTY(lcRow), "", ",") + ;
TRANSFORM(EVALUATE(laFields[lnFields,1]))
ENDIF
ENDFOR
FWRITE(lnHandle, lcRow)
ENDSCAN
FCLOSE(lnHandle)