AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Question about DBI and single-quote delimeter (https://forums.alliedmods.net/showthread.php?t=5563)

Mugwump 09-05-2004 13:52

Question about DBI and single-quote delimeter
 
Since character fields are generally delimeted by single quotes, if i want to insert a character string like player name that may contain a single-quote or use a WHERE clause and do a comparison against a sting that might contain a single-quote how would I escape the single quote in that string variable?

In perl this is easy,

Code:

$name =~ s/'/\\'/g;
but I am not so sure how to do this in small.

Thanks :)
Mug

BAILOPAN 09-05-2004 14:43

replace?

Mugwump 09-05-2004 14:51

Ahhh, well that makes sense... ;)

So something like this:

while ( replace( sName, "'", "\\'") ){ }

or instead of \\' do I use ^' , I'm unclear ?

Thanks Bail!
-Mug

devicenull 09-05-2004 15:03

replaceall :)
Its a function thats floating around on the forums somewhere, just search for it

Johnny got his gun 09-06-2004 05:31

Code:
stock replaceall(text[], const LEN, const WHAT[], const WITH[]) {     while (contain(text, WHAT) != -1)         replace(text, LEN, WHAT, WITH) }

And yes, the escape character is the ^

Mugwump 09-08-2004 17:23

replaceall is not a viable solution assuming this is what I wanted to do:

replaceall(name, 32, "'", "^'")

It gets caught in an infinite loop because the index of containi isn't updating as it finds a single-quote

So am I the first person thats wanted to do this or is there some other way that hasn't been suggested yet? :)

EDIT: I checked string.inc and there does not seem to be a version of contain where you can pass the starting index to search from, that'd be a big help.

-Mug

PM 09-08-2004 17:38

:D :D :D :up: contain(string[startchar], ...) :up: :D :D :D

Might work

Mugwump 09-09-2004 10:24

Will give it a try, thanks PM!

-Mug


All times are GMT -4. The time now is 17:27.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.