C like escape sequenses for strings.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

C like escape sequenses for strings.

Post by Tipperton »

That way we could do something like

Code: Select all

msg.s = "Hello\nThere!"
instead of having to do

Code: Select all

msg.s = "Hello" + Chr(13) + Chr(10) + "There!"
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 575
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Post by bembulak »

Yes, this would be good! I like those Escape squences, also for TABS, ....
cheers,

bembulak
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

So all filenames must be written like this: "C:\\Program Files\\..." brrr! :P
quidquid Latine dictum sit altum videtur
WishMaster
Enthusiast
Enthusiast
Posts: 277
Joined: Fri Jun 17, 2005 7:13 pm
Location: Franconia
Contact:

Post by WishMaster »

I personally don't think that's a good idea.
For users, maybe. But not for programmers...
Image Image
gogo
User
User
Posts: 11
Joined: Wed Jan 31, 2007 11:18 am
Location: France

Post by gogo »

I like verbatim strings as found in C# ....

Code: Select all

string s=@"bla bla bla c:\folder\file.ext
and I can continue on next line 
and another line ";
Ok, the @ is used for getting the address. In PB we just need to find another character.
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 »

freak wrote:So all filenames must be written like this: "C:\\Program Files\\..." brrr! :P
and URL: "http:////www.purebasic.com//index.html" :shock:
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:and URL: "http:////www.purebasic.com//index.html" :shock:
lol no, why do you think that?
Good programmers don't comment their code. It was hard to write, should be hard to read.
SCRJ
User
User
Posts: 93
Joined: Sun Jan 15, 2006 1:36 pm

Post by SCRJ »

msg.s = "This is useful\nPlease add this :D "
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: C like escape sequenses for strings.

Post by Joakim Christiansen »

Tipperton wrote:That way we could do something like

Code: Select all

msg.s = "Hello\nThere!"
instead of having to do

Code: Select all

msg.s = "Hello" + Chr(13) + Chr(10) + "There!"
Just do like me! :P

Code: Select all

msg.s = "Hello"+#LF$+"There!"
Last edited by Joakim Christiansen on Thu Feb 01, 2007 10:55 pm, edited 1 time in total.
I like logic, hence I dislike humans but love computers.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

No I don't want it.

Code: Select all

msg.s = "Hello" + #CRLF$ + "There!"
SCRJ
User
User
Posts: 93
Joined: Sun Jan 15, 2006 1:36 pm

Post by SCRJ »

Maybe as a compiler option?
Clutch
User
User
Posts: 52
Joined: Sun Nov 26, 2006 6:11 am
Location: South Florida

Post by Clutch »

Trond wrote:No I don't want it.
Agreed.
"Ahead one third... ahead two thirds... Full ahead flank
And out from the belly of the whale came a prophet, Amen"
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

SCRJ wrote:Maybe as a compiler option?
That's even worse! It should be EnableEscape and DisableEscape in the source file.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

I must say that sometimes escape sequences are useful.

but a simple procedure do the trick.

pb team might include this function as an optimized one - something like that :

String$ = EscapeString(EscapedString$)

Code: Select all

Procedure.s EscapeString(string.s) ; purebasic function (in string library)
  string = ReplaceString(string, "\\", "\")
  string = ReplaceString(string, "\t", #TAB$)
  string = ReplaceString(string, "\n", #CRLF$)
  ProcedureReturn 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\\"))

No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Chrono Syndrome
Enthusiast
Enthusiast
Posts: 169
Joined: Thu Oct 05, 2006 6:44 am
Contact:

Post by Chrono Syndrome »

2Flype: Khe-khm... Try this: "\\no problems ?"
Don't try to catch ze Night !
Remember: 'z' is better zen 'th' =) !
Sorry for bad english.
Post Reply