Re: How to get a doubleQuote into a string ?
Posted: Sat Feb 07, 2015 11:50 pm
Pls, What is the diff between #DQ$ and DQ$ ? Thanksskywalk wrote:Code: Select all
#DQ$ = Chr(34) MyString$ = #DQ$ + "Hello" + #DQ$ debug MyString$
http://www.purebasic.com
https://www.purebasic.fr/english/
Pls, What is the diff between #DQ$ and DQ$ ? Thanksskywalk wrote:Code: Select all
#DQ$ = Chr(34) MyString$ = #DQ$ + "Hello" + #DQ$ debug MyString$
Oh, ya, ThanksStarBootics wrote:Another way around :
Code: Select all
MyString$ = Chr(34) + "Hello" + Chr(34) Debug MyString$
Ah, What fun! I have downloaded this whole page.idle wrote:wrapping it in a macro is perhaps more convenient
Code: Select all
Macro DQ(text) #DQUOTE$ + text + #DQUOTE$ EndMacro mystring.s = DQ("foo") + "," + DQ("bar") Debug mystring
Code: Select all
;From: OpenFile_Example.pb , Author: wayne1 (updated for PB4.00 by blbltheworm)
;input data generated fron ProgramName: xRainbow-vera.pb
Define.s OneLines = "Z00,000,FAE0D9"
Define.s TBox02$ , DQ$ = Chr(34)
Define.i OneLinei , x , y , CommaCnt , CountLinesOut
Global FileOpen = 0 , OneLine$="" , OneLiner$="" , OneLineByte$=""
Global TableBeg$ = "<TABLE>"
Global LTTD01$,LTTD02$,QTGT01$,TD02$,TD01$,TBox02dot$
;Structure TableRow
; TRbeg.s = "<TR>"
; TDbeg01a.s = "<TD style= + DQ$ + color:black + DQ$ + "
; TBox01.s = "000,000,FFFFFF"
; TDbeg01b.s = ">"
; TDbeg02a.s = "<TD BGCOLOR = + DQ$ + #"
; TBox02.s ; = "FFFFFF"
; TDbeg02b.s = ">"
; TDend.s = "</TD>"
; TRend.s = "</TR>"
;EndStructure
Procedure LoadHexColor(OneLine$)
OneLinei = StringByteLength(OneLine$, #PB_Ascii)
CommaCnt = 0 : TBox02$ = ""
For x = 1 To OneLinei
OneLineByte$ = Mid(OneLine$, x, 1)
If OneLineByte$ = ","
CommaCnt = CommaCnt +1
EndIf
If OneLineByte$ <> ","
If CommaCnt > 1
TBox02$ = TBox02$ + OneLineByte$
EndIf
EndIf
Next
TBox02.s = TBox02$ ; loadup TableRow.TBox02.s
TBox02dot$ = TBox02$
EndProcedure ; LoadHexColor()
Procedure FileOut(OneLine$)
If FileOpen = 0
If CreateFile(2, "ColorTable.html")
FileOpen = 1
WriteStringN(2,"<!DOCTYPE HTML PUBLIC" + DQ$ + "-//W3C//DTD HTML 4.01 Transitional//EN " + DQ$ + ">")
WriteStringN(2,"<html><head>")
WriteStringN(2,"<meta charset=" + DQ$ + "utf-8" + DQ$ + "><title>xRainbow-Project</title>")
WriteStringN(2,"<style>")
WriteStringN(2,"table td {border: 1px solid black; color: Black;}</style>")
WriteStringN(2,"</head><body>")
WriteStringN(2,TableBeg$)
Else
MessageRequester("PureBasic", "Error: can't Create file", 0)
End
EndIf ; CreateFile(2,
EndIf ; FileOpen = 0
LoadHexColor(OneLine$)
LTTD01$ = "<TR><TD style="+DQ$+"height:50px; background-color:#"+TBox02dot$+";"+DQ$+">"+OneLine$+"</TD>"
TD01$ = LTTD01$ + TBox01.s ;+ "</TD>"
WriteStringN(2, TD01$)
OneLine$ = ""
EndProcedure ;FileOut(OneLine$)
Procedure OFile(file.s)
d=ReadFile(1, file)
If d
While Eof(1)=0
Text$ = ReadString(1) ; +Chr(13)+ Chr(10)
OneLine$ = Text$ ; "testing line"+"<br>" ; TableRow
TBox01.s = OneLine$
CountLinesOut+1
FileOut(OneLine$)
If CountLinesOut > 3
Break
EndIf
Wend
CloseFile(1)
WriteStringN(2,"</TABLE></body></html>")
CloseFile(2)
SetGadgetText(2, Text$)
Else
MessageRequester("Error","No valid file was selected.",#MB_ICONERROR)
EndIf
MessageRequester("#Lines Out =",Str(CountLinesOut))
EndProcedure ;OFile(file.s)
If OpenWindow(0, 100, 200, 495, 260, "Open Small Files Example", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
ButtonGadget(1,210,20,80,25,"Open File")
StringGadget(2,10,60,480,185,"",#ES_MULTILINE | #ES_AUTOVSCROLL|#WS_VSCROLL|#WS_HSCROLL)
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
Quit = 1
EndIf
If EventID = #PB_Event_Gadget
Select EventGadget()
Case 1
file$ = "xRainbow-Vera-CommaS.txt"
OFile(file$)
EndSelect
EndIf
Until Quit = 1
EndIf
End#DQ$ is a constant I defined to keep a shorter name than the existing #DQUOTE$. DQ$ is a string variable. A variable can be changed, the constant cannot(without trickery in a DataSection).vmars316 wrote:Pls, What is the diff between #DQ$ and DQ$ ? Thanks
vmars316 wrote:I am still having trouble writing DoubleQuotes into Html code.
Hi vmars316. The DQ$ variable did not work because it was utilised within the FileOut() procedure, but declared outside of that scope. It would work if it is declared as a global variable, or a local variable within the procedure itself; like so:vmars316 wrote:Aha, when I plugged the #DQ$ in there, the doubleQuotes now show up in the html-code...
Code: Select all
Define.s OneLines = "Z00,000,FAE0D9"
Define.s TBox02$
Global DQ$ = Chr(34)
...Code: Select all
Procedure FileOut(OneLine$)
Define DQ$ = Chr(34)
...Code: Select all
a = 1 ;a is an integer by default
a$ = "Hello" ;a$ is a string by default
b = "Hello" ;raises error [Trying to write a string into a numerical variable]
b.s = "Hello" ;must be explicitly defined with the string type suffix [.s]Code: Select all
OneLine$ = "0,0,E6E9FE"
Debug OneLine$
Debug Right(OneLine$, 6)Code: Select all
; LTTD01$ = "<TR><TD style="+#DQ$+"height:50px; background-color:#"+TBox02dot$+";"+#DQ$+">"+OneLine$+"</TD>"
LTTD01$ = "<TR><TD style=" + #DQ$ + "height:20px; background-color:#" + Right(OneLine$, 6) + ";" + #DQ$ + ">" + OneLine$ + "</TD>"