Escape double quotes in string in crystal report - crystal-reports-2010

How to do escape double quote in crystal report function
My Code:
Function GetResult()
Dim Result As String
if () the
Result = "ckl"B"
else
end if
Note: I am using basic syntax for function

There is no need to write a function ..Simply way is
replace({table.field},"""","" ) or
replace({table.field},chrW(34),"" )

Related

ruby on rails replace single-quotes with double-quote in a string

I am trying to replace a single-quote with double quotes inside a string, as following:
current_res = 25
lowest_res = 15
str = "The result of the child is '#{current_res}' and the lowest grade is '#{lowest_res }'."
I need the output to look like:
str = The result of the child is "25" and the lowest grade is "15".
I tried different method using gsub but nothing work so far. Any ideas?
If that's the only case you're covering where you need to show some output in double quoted string then. How about something simple like following
str = "The result of the child is \"#{current_res}\" and the lowest grade is \"#{lowest_res }\" ."
You can escape quotes in double quoted strings.

Replace double backslashes with single backslash using JS223 processor

I have a variable (CONTEXTTOKEN) which I extract in JMeter using a Boundary Extractor. This variable has double backslashes as below:
I am using a JS223 processor to try and replace the double backslashes with a single one like this:
def myVariable = vars.get("CONTEXTTOKEN")
def request = myVariable.replaceAll("\\", "\")
vars.put("CONTEXTTOKEN", request)
However when I run my script CONTEXTTOKEN still has double backslashes
Ok I resolved this by doing a .toString().replace("\\\\","\\").

hidden space in excel

I tried almost all the methods (CLEAN,TRIM,SUBSTITUTE) trying to remove the character hiding in the beginning and the end of a text. In my case, I downloaded the bill of material report from oracle ERP and found that the item codes are a victim of hidden characters.
After so many findings, I was able to trace which character is hidden and found out that it's a question mark'?' (via VBA code in another thread) both at the front and the end. You can take this item code‭: ‭11301-21‬
If you paste the above into your excel and see its length =LEN(), you can understand my problem much better.
I need a good solution for this problem. Therefore please help!
Thank you very much in advance.
Thanks to Gary's Student, because his answer inspired me.
Also, I used this answer for this code.
This function will clean every single char of your data, so it should work for you. You need 2 functions: 1 to clean the Unicode chars, and other one to clean your item codes_
Public Function CLEAN_ITEM_CODE(ByRef ThisCell As Range) As String
If ThisCell.Count > 1 Or ThisCell.Count < 1 Then
CLEAN_ITEM_CODE = "Only single cells allowed"
Exit Function
End If
Dim ZZ As Byte
For ZZ = 1 To Len(ThisCell.Value) Step 1
CLEAN_ITEM_CODE = CLEAN_ITEM_CODE & GetStrippedText(Mid(ThisCell.Value, ZZ, 1))
Next ZZ
End Function
Private Function GetStrippedText(txt As String) As String
If txt = "–" Then
GetStrippedText = "–"
Else
Dim regEx As Object
Set regEx = CreateObject("vbscript.regexp")
regEx.Pattern = "[^\u0000-\u007F]"
GetStrippedText = regEx.Replace(txt, "")
End If
End Function
And this is what i get using it as formula in Excel. Note the difference in the Len of strings:
Hope this helps
You have characters that look like a space character, but are not. They are UniCode 8236 & 8237.
Just replace them with a space character (ASCII 32).
EDIT#1:
Based on the string in your post, the following VBA macro will replace UniCode characters 8236 amd 8237 with simple space characters:
Sub Kleanup()
Dim N1 As Long, N2 As Long
Dim Bad1 As String, Bad2 As String
N1 = 8237
Bad1 = ChrW(N1)
N2 = 8236
Bad2 = ChrW(N2)
Cells.Replace what:=Bad1, replacement:=" ", lookat:=xlPart
Cells.Replace what:=Bad2, replacement:=" ", lookat:=xlPart
End Sub

In Grails and Groovy, do Strings (in single quotes) outperform GStrings?

Since in Grails and Groovy, single-quoted Strings are different class from GStrings (double quoted Strings allowing ${variable} value injection), is it more efficient to use single quotes, except when ${variables} are being used? I am guessing that the presence of the double quotes would require parsing of the String that an ordinary single-quoted String would not require. Therefore I would expect a very slight performance hit from the extra time looking for the presence of the ${}.
So, it would seem that it would be beneficial in general to have a convention to encourage the use single quotes, unless there is a specific advantage to using the double quotes. Am I off base?
Take a look at the first note under Double Quoted String.
Double quoted strings are plain java.lang.String if there’s no
interpolated expression, but are groovy.lang.GString instances if
interpolation is present.
This is possible because the interpolation is detected lazily and therefore determined whether to refer it as a GString or String. For example try to assertions below:
assert 'sample'.class.simpleName == 'String'
assert "sample".class.simpleName == 'String'
assert "sample ${1 != 2}".class.simpleName == 'GStringImpl'
Second assertion above makes it clear that double quotes are String by default until there is an interpolation (as in third assertion).
So, it does not matter if single or double quotes are used for as long as interpolation is not present. However, I personally do not think there should be any worry about performance benefits at the scale of using String or GString.
is it more efficient to use single quotes, except when ${variables}
are being used?
No. For the scenario where no ${variables} are used, they perform exactly the same. If there are no ${variables} in a double quoted String then the system does not create a GString. It creates a standard java.lang.String.
EDIT To Address A Separate Question Posted In A Comment Below:
It happens at compile time. The code below:
void someMethod(String a) {
def s1 = "some string"
def s2 = "some string with arg ${a}"
}
#groovy.transform.CompileStatic
void someOtherMethod(String a) {
def s1 = "some string"
def s2 = "some string with arg ${a}"
}
Compiles to this:
public void someMethod(String a)
{
CallSite[] arrayOfCallSite = $getCallSiteArray();
Object s1 = "some string";
Object s2 = new GStringImpl(new Object[] { a }, new String[] { "some string with arg ", "" });
}
public void someOtherMethod(String a)
{
String s1 = "some string";
GString s2 = new GStringImpl(new Object[] { a }, new String[] { "some string with arg ", "" });
}

Escape and replace quotations in VBS

I need to escape the character " by replacing it in vbs
I write
str=8505usafromTo^1c0"ma
str = replace(str,chr(34),"""")
But it seems like " does not escape for the string str
Please, what's wrong and someone could help me fix that?
Thanks
String literals need double quotes:
str = "8505usafromTo^1c0 ma"
To escape a double quote in a string literal, use "" (double double quotes)
str = "8505usafromTo^1c0""ma"
It makes no sense to a replace double quotes (Chr(34)) in a string with double quotes ("""").
Update:
If you .ReadAll()/.ReadLine() a string from a file and want to change the " in that string, use
str = Replace(str, """", "that's what I want to see instead of each double quote")
In case you want "" (double double quotes) as replacements, you need """""" (2 delimiters and two times two double quotes).

Resources