How to get the substring from a String in ColdFusion - string

How can I get the Substring in Coldfusion?
ex:- following is the String "Update Tablename set value=something where value2=thisone"
I want to get the Table name from the Str
how is it possible?
Note:- Table name is dynamic(i.e may be any charecters).
Thanks

updated:
You can probably use result = ListToArray(sql , " ") and then use the result[2]
also i believe you can do ListGetAt(sql, 2, " ")

Related

Error : can only concatenate str (not "int") to str

please help I can't fix this one I'm stuck here for 2 hours ago I can't pass this
when I input only one username it's ok but if I input more then one username it's an error like the title
I want output like this
Your problem is that you are replacing your counter (cnt) with a string:
cnt = str(cnt)
Use a different variable name for the string variable, such as:
cnt_str = str(cnt)

What is the best way to pass multiple string variables to a query string in python3

I need to create a dynamic query based on two string parameters:
description = "This is the description"
comment = "This is the comment"
query = "insert into case(desc, comm) value(description, comment)"
Note:
there might be single quote and double quotes in both description and comment.
How do I use formatted %s to generate the query string?
Thank you very much.
UPDATE:
Thanks to Green Cloak Guy (his/her answer has minors to be corrected), the right query is:
query = f"insert into case(description, comment) value(\'{description}\', \'{comment}\')"
Use an f-string.
query = f"insert into case({description}, {comment}) value({description}, {comment})"
Don't use any type of string formatting to do actual database queries - that leads to you having a SQL Injection problem. Use a database library instead, that properly sanitizes the data.
But if all you need to do is parse some variables into a string, this is more flexible than the % formatting that other languages tend to use (and that's technically still available in python via "some_string %s %s %s" % (str1, str2, str3)")

Find index of a specific character in a string then parse the string

I have strings which looks like this [NAME LASTNAME/NAME.LAST#emailaddress/123456678]. What I want to do is parse strings which have the same format as shown above so I only get NAME LASTNAME. My psuedo idea is find the index of the first instance of /, then strip from index 1 to that index of / we found. I want this as a VBScript.
Your way should work. You can also Split() your string on / and just grab the first element of the resulting array:
Const SOME_STRING = "John Doe/John.Doe#example.com/12345678"
WScript.Echo Split(SOME_STRING, "/")(0)
Output:
John Doe
Edit, with respect to comments.
If your string contains the [, you can still Split(). Just use Mid() to grab the first element starting at character position 2:
Const SOME_STRING = "[John Doe/John.Doe#example.com/12345678]"
WScript.Echo Mid(Split(SOME_STRING, "/")(0), 2)
Your idea is good here, you should also need to grab index for "[".This will make script robust and flexible here.Below code will always return strings placed between first occurrence of "[" and "/".
var = "[John Doe/John.Doe#example.com/12345678]"
WScript.Echo Mid(var, (InStr(var,"[")+1),InStr(var,"/")-InStr(var,"[")-1)

Grails string replace not working?

I have an object being passed to the controller from a view and it contained double spaces in it that I need to remove. I have gone down the standard path and used the correct functionality to try and remove these double spaces but it doesn’t work. The string did also have a space at the from and then end that I managed to remove with .trim().
Below is what I used to try and Replace all the double spaces:
object = params.objectValue.trim()
object.replaceAll(" ", " ")
This did not work and still had the spaces so I tried this:
newObj = ""
object = params.objectValue.trim()
newObj = object
newObj.toString().replace(" ", " ")
here is an example of the string text:
"the person drove the car on 21/12/04 at 12:00"
This didn’t work either, has anyone got any idea as i dont really understand what i can do to remove these double spaces?
Thanks in advance
replaceAll() doesn't mutate the original string, it returns a new string with the replaced elements. You need to reassign params.objectValue to the result of replaceAll()
params.objectValue = params.objectValue.replaceAll(" ", " ").trim()

Alternative to CONTAINS method?

Giving the string below with "server type" separated by comma:
string serverTypeList = "DB, IIS, CMDB";
//server.Type in the loop below should have value of "MDB"
My problem is that in this scenario it will return TRUE because "MDB" string is inside the serverTypeList.
I need it to return TRUE only if it matches a type of "MDB" and not "CMDB":
...
from site in SiteManager.Sites
from server in site.Servers
where
serverTypeList.Contains(server.Type)
select new Server()
{ ID=server.ID, SiteName=site.Name }
...
How can I change the code above?
Thank you
(", " + serverTypeList + ", ").Contains(", " + server.Type + ", ")
is one standard way to handle this. I'm not clear on the language you're using, so I don't know the exact syntax you would need, but the general idea is to ensure that the term appears between delimiters by forcing delimiters before and after the list string.

Resources