C like escape sequenses for strings.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 575
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Post by bembulak »

freak wrote:So all filenames must be written like this: "C:\\Program Files\\..." brrr!
You're right. I didn't think about that ...
cheers,

bembulak
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

traumatic wrote: lol no, why do you think that?
oh, is slash, no backslash :oops:
More coffee please :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

ts-soft wrote:More coffee please :wink:
;)
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Chrono Syndrome wrote:2Flype: Khe-khm... Try this: "\\no problems ?"
i hope this version fix it:

Code: Select all

Procedure.s EscapeString(string.s)
  ReplaceString(string, "", "|", 2)
  Protected *c.Character = @string
  While *c\c <> 0
    If *c\c = '|'
      *c + SizeOf(Character)
      Select *c\c
        Case '|' : *c\c = '\'
        Case 'a' : *c\c =  7 ; bel
        Case 'b' : *c\c =  8 ; backspace
        Case 't' : *c\c =  9 ; Tab
        Case 'l' : *c\c = 10 ; linefeed
        Case 'f' : *c\c = 12 ; formfeed
        Case 'r' : *c\c = 13 ; return
        Case 'n'             ; carriage return
          *c - SizeOf(Character)
          *c\c = 13
          *c + SizeOf(Character)
          *c\c = 10
        Case 'q'  : *c\c = 34 ; dquote
      EndSelect
    EndIf
    *c + SizeOf(Character)
  Wend
  ProcedureReturn ReplaceString(string, "|", "")
EndProcedure

Macro esc(string) ; user defined
  EscapeString(string)
EndMacro

MessageRequester("", esc("*\tHello\t\t*\n*\tThere!\t\t*"))
MessageRequester("", esc("C:\\Program Files\\PureBasic\"))
MessageRequester("", esc("\qTest in Dquote\q"))
MessageRequester("", esc( "\\no problems ?"))
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
gogo
User
User
Posts: 11
Joined: Wed Jan 31, 2007 11:18 am
Location: France

Post by gogo »

:twisted: Just a question : How do you escape the double-quote (") character ..... This is why it should be done on the compiler side.

A lot of you are scared by strings like this one :
"D:\\PureBasic\\Examples\\Sources\\2DDrawing.pb"
I can admit that it's very boring to use \\ to escape the \ . But, I think that all opponents of the backslash are not aware of the validity of the slash in windows filenme. I just cant remember the last time I typed file paths with backslashes.
This works perfectly on Win32 :

Code: Select all

OpenConsole()
hf = ReadFile(#PB_Any,"D:/PureBasic/Examples/Sources/2DDrawing.pb")
While Eof(hf) = 0
    PrintN(ReadString(hf))
Wend

Input()
CloseConsole()
Only UNC name must keep the "\\" in front of the computer name. After you can continue with "/"
e.g:

//mycomputer is not valid
\\mycomputer/myshare/folder is valid
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

gogo wrote::twisted: Just a question : How do you escape the double-quote (") character ..... This is why it should be done on the compiler side.

Code: Select all

"\q"
see the code above, is implemented
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
gogo
User
User
Posts: 11
Joined: Wed Jan 31, 2007 11:18 am
Location: France

Post by gogo »

:? oops :( I should read the code before posting.

But what I want to say is that I cant understand arguments of the anti-backslash lobby. They don't want it because of the windows paths. But they can use the slash. I've seen some jokes with "http:////". We never said that the slash character is the escape character.

If you think that escape character are for insane minds, take a look at regular expressions :shock:
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Trond wrote:No I don't want it.

Code: Select all

msg.s = "Hello" + #CRLF$ + "There!"
Agreed +1

(however, as long as we're changing the language, there is some cobol syntax I think we should adopt :D
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

Trond wrote:

Code: Select all

msg.s = "Hello" + #CRLF$ + "There!"
Is that #CRFL$ something you defined or pre-defined? And if it's pre-defined, where is the documentation about it and all the other pre-defined things like it? I just did a search of the help file and found nothing.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Tipperton wrote:
Trond wrote:

Code: Select all

msg.s = "Hello" + #CRLF$ + "There!"
Is that #CRFL$ something you defined or pre-defined? And if it's pre-defined, where is the documentation about it and all the other pre-defined things like it? I just did a search of the help file and found nothing.
#CRLF$ = chr(13) + chr(10)

Its something anyone can do on his own code

#Eof = chr(13) + chr(10)

Is the one i use.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Tipperton wrote:
Trond wrote:

Code: Select all

msg.s = "Hello" + #CRLF$ + "There!"
Is that #CRFL$ something you defined or pre-defined? And if it's pre-defined, where is the documentation about it and all the other pre-defined things like it? I just did a search of the help file and found nothing.
It's predefined. Take a look at the constants tab in the structure viewer.
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

Tipperton wrote:
Trond wrote:

Code: Select all

msg.s = "Hello" + #CRLF$ + "There!"
Is that #CRFL$ something you defined or pre-defined? And if it's pre-defined, where is the documentation about it and all the other pre-defined things like it? I just did a search of the help file and found nothing.
Look at the Table with ASCII-Codes their depending figures in purebasic.chm. In the first column there are named ascii codes (NUL to US), you can use those names as constants (#US) to get the ascii code or as string constants (#US$) to get it as a string... But you're right there is nothing written about that...

Dri
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Dr. Dri wrote:But you're right there is nothing written about that...Dri
The manual says that the structure viewer allows you to view all constant that are predefined in PureBasic. Those constants are written in the list of constants. Where else should the be written?
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

The problem is that having the list of constants itself is not enough IMHO
If i see a SOH constant i wont be able to say what it means...

Dri
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Escaping "

Post by Crusiatus Black »

I have an proceduredll script that also replaces the " character for a binary value, but by using \q is not replacing " for the binary numbers...

How can i escape this character?
Post Reply