golang define variable with newline [duplicate] - go

This question already has answers here:
How do you write multiline strings in Go?
(12 answers)
Closed 2 years ago.
How do you define variable value that includes new line?
const statement = "SELECT *
FROM `users` u;";
It shows error newline in string.

You would normally use a raw string literal like this
const s = `first line
second line`
However, this is not possible in your case since the string itself contains backticks. In this case I would use + to connect the lines:
const statement = "SELECT *" +
" FROM `users` u;";
The string value in this example does not contain a newline (but that's ok for SQL). If you really want a newline in the string, use the escape sequence \n.
const s = "first line\nsecond line"

Related

Update query not working and asking for substitue in Oracle [duplicate]

This question already has answers here:
How to avoid variable substitution in Oracle SQL Developer
(5 answers)
Enter Substitution Variable
(3 answers)
How to insert a string which contains an "&"
(14 answers)
Closed 12 months ago.
I have a query where I want to update like below
update tbl_fiber_inv_job_progress
set ums_group_ass_by_id = 626,
ums_group_ass_by_name = 'Construction_Engineer',
ums_group_ass_to_id = 622,
ums_group_ass_to_name = 'O&M Fiber Engineer', --
approv_reject_remark = 'Reoffered',
modified_by = 'ORA SCHEDULER',
modified_date = SYSDATE
where job_id = 32905;
But getting error as
Enter value for M
Please help
I think the cause of your problem is the & character in the next line:
ums_group_ass_to_name = 'O&M Fiber Engineer',
If you use SQLPlus try this line:
set define off;
The & character is used to identify substitution variables in several scripting engines like sqlplus and TOAD. You need to escape that character in the string, so that it can be interpreted correctly. Try this:
ums_group_ass_to_name = 'O\&M Fiber Engineer',
or place this command before your DML in the script:
set define off;

String Split with Multiple Delimeters [duplicate]

This question already has answers here:
Splitting on comma outside quotes
(5 answers)
Closed 1 year ago.
How can I split the string to multiple substrings?
String = "5260,GOODS,4,10,TISSUE,,84,\"1,008\",24,24,,,78,84,24";
I was spliting the string to string[] by using comma separator ","
But One value contains comma - \"1,008\"
Is there any way to get the string as
Expected Output -
"5260,GOODS,4,10,TISSUE,,84,1008,24,24,,,78,84,24";
You have to "normalize" your text first by:
option 1:
convverting all false positives in other format that skip the split.. i.e. you need to change (maybe with regex) the value 1,008 to something like 1.008
option 2:
changing all the "," everyhere for another char(example ":") not present in the string but keeping the value 1,008 and split to ":"

How do I use LIKE in IF statement properly in ASP Classic? [duplicate]

This question already has answers here:
VBS using LIKE to compare strings "Sub or Function not defined"
(4 answers)
Closed 1 year ago.
I have a IF statement where I need to use LIKE to determin if the result set contains an e-mail address, and this is similar to the session ADMail .. the initial code I have tried with is :
UserEmailForTask = Session("ADmail")
IF objGetTaskEmailsSettings("IT_Email") LIKE %UserEmailForTask% OR Session("ADdepartment") = "IT" THEN
Dim IT_User_Tasks
IT_User_Tasks = "YES"
END IF
objGetTaskEmailsSettings("IT_Email") can contain eigther "user1#mail.com" or have multiple emails inside it like "user1#mail.com,user2#mail.com,user3#mail.com" where I need to check if the email in UserEmailForTask is included.
Obviously I will get a fail on %UserEmailForTask%when using this, but how do I solve this?
The InStr function returns the position of the first occurrence of one string within another. Use it to check if the given string contains the search string:
UserEmailForTask = "..."
IF InStr(objGetTaskEmailsSettings("IT_Email"),UserEmailForTask)>0
OR Session("ADdepartment") = "IT" THEN
Dim IT_User_Tasks
IT_User_Tasks = "YES"
END IF

How to remove first 3 characters in a string [duplicate]

This question already has answers here:
How Do I Use VBScript to Strip the First n Characters of a String?
(4 answers)
Closed 6 years ago.
I have a program that prints a string to a notepad file, the output being something random:
#'f7ruhigbergbn
I want to however remove the first 3 characters from the pasted result, how can I do this?
myString = "#'f"
result = workings - myString
This does not work, bare in mind the first 3 characters are always going to be #'f
Any thoughts? thanks
You can use:
result = Mid(workings, 4)
You can use Right function for get the X characters of the right side of string. With Len function you can get the length of the string.
Right(myString,Len(myAtring) - 3)
With this, you get a new string whitout the three first characters, now you can assign to the same string:
myString = Right(myString,Len(myAtring) - 3)
Try this:
mystring = "#'f7ruhigbergbn"
result = Mid(mystring, 3, mystring.length)

What does the back tick do in golang

I have a variable defined like this
var selectStatement = `
SELECT role FROM abc INNER JOIN xyz ON (abc.name = 'Service list')
`
Now what I want to do is instead of using hardcoded 'Service list' I want to read a variable value something like
var myvar = "operation"
var selectStatement = `
SELECT role FROM abc INNER JOIN xyz ON (abc.name = $myvar)
`
I know its very simple if there was "string" instead of `string`.
How can I achieve this. What is the difference between "string" and `string`?
` That back tick, (on the tilde key) is for declaring string literals. It makes it so you can have quotes and new lines and they are interpreted literally rather than breaking the string.
To solve your bigger problem use fmt.Sprintf so...
var selectStatement = `
SELECT role FROM abc INNER JOIN xyz ON (abc.name = '%s')
`
selectStatement = fmt.Sprintf(selectStatement, ValueGoingWherePercentSIsNow)
This question is actually two questions: one in a topic and one in a body of the question.
What does ` do in GoLang
`string` is a raw string literal. In a raw string literal (within the quotes) any character may appear except backquote. A raw string literal is uninterpreted (implicitly UTF-8-encoded) characters. It means that backslashes have no special meaning and the string may contain newlines.
"string" is an interpreted string literal. With interpreted string literal backslash escapes interpreted as they are in rune literals. It can't contain newlines, although the escape sequence \n is interpreted as a newline.
String interpolation
It is possible to do with fmt.Sprintf
func main(){
myvar := "operation"
selectStatement := `
SELECT role FROM abc INNER JOIN xyz ON (abc.name = %s)
`
interpolated := fmt.Sprintf(selectStatement, myvar)
}
Playground

Resources