|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Problems with blank spaces
Hi there. I'm trying to delete ' from strings that i'm going to use in a SQL query. I have this now:
function RemoveChars(input) input = Replace(input,"'","") End Function The thing is, all the ' will turn into blanks(spaces) and I need to get rid of them as well, so i tried this: function RemoveChars(input) input = Replace(input,"'","") inout = Trim(input) End Function But it didn't work. Any suggestions? Also, should I have a: Response.Write input in the bottom before End function? When should I add that string? Thanks Seeker |
|
#2
|
||||
|
||||
|
Why do you need to get rid of them?
|
|
#3
|
|||
|
|||
|
This is my code:
function RemoveChars(input) input = Replace(input,"'","") Response.Write input End Function Strkeyword = RemoveChars(request.form("keyword")) if strkeyword ="" then response.redirect("search.asp?name=Search&msg=typekeyword") end if It will give me a Strkeyword = "" which it shouldn't ? I will also use the Strkeyword as: rs = "SELECT * FROM users where user LIKE '%"&strkeyword&"%' OR d LIKE '%"&strkeyword&"%'" set sql = connect.execute(rs) //Seeker |
|
#4
|
||||
|
||||
|
You didn't answer my question.
WHY do you need to remove the (') single quotes? |
|
#5
|
|||
|
|||
|
Quote:
^^ That is why. You are problaby aware of the complications when trying to make a SQL query when there are (')s in it. I don't understand why my function won't work? |
|
#6
|
||||
|
||||
|
You don't need to remove them, just double them.
Code:
strSql = "SELECT * FROM [users] WHERE username LIKE '%" & ReplaceQuotes(strKeyword) & "%' OR d LIKE '%" & ReplaceQuotes(strKeyword) & "%'" Set rs = Conn.Execute(strSql) Function ReplaceQuotes(strValue) strValue = Replace(strValue, "'", "''") ReplaceQuotes = strValue End Function |
|
#7
|
|||
|
|||
|
Ok thank you mat, that will come in handy.
But let's pretend I'd like to remove them instead, just for learning, how should i do? Why won't my original function work?? //Seeker |
|
#8
|
||||
|
||||
|
You weren't returning the value in your function.
Do this. Code:
strValue = "Mark's" Response.write(RemoveChars(strValue)) Function RemoveChars(input) input = Replace(input,"'","") RemoveChars = input End Function |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > Problems with blank spaces |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|