I want to remove all control character from the given string. i don't want to use Replace method because it take multiple iteration.
Help me.
Thanks in advance.
You may not like it, but REPLACE is the simplest way to do it. I've used this code to strip non-printable characters from a string. This will replace the control characters with a space:
DEFINE VARIABLE str AS CHARACTER NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
DO iLoop = 1 TO 31:
str = REPLACE(str, CHR(iLoop), " ").
END.
Since there are multiple control characters that have to be removed, it seems that any solution will involve multiple iterations.
Depending on what you define as a control character and what character set you are using this might do the trick. Or at least point you in a helpful direction:
define variable i as integer no-undo.
define variable n as integer no-undo.
define variable c as character no-undo.
define variable s as character no-undo.
define variable x as character no-undo.
s = "something with control characters in it".
x = "".
n = length( s ).
do i = 1 to n:
c = substring( s, i, 1 ).
if asc( c ) >= 32 and asc( c ) < 127 then
x = x + c.
end.
Related
What I know so far ...
1) Backticks are used when creating tibbles with non-syntactic variable/column names that contain numbers, spaces, or other symbols (because normally you can only name columns with letters right?)
tb <- tibble(
': ) ' = "smile, ' ' = "space",
'2000' = "number", "double_quotes" = "normal_text")
However, when I use double quotes here the tibble still forms with the nonsyntactic symbols/numbers.
2) Double quotes are used to subset column names when using double brackets.
tb[["double_quotes"]]
And here, when I use single quotes to subset, it still works as well.
3) When subsetting using $, to select for nonsyntactic names, I must use single quotes, but here again, if I subset using double quotes, it works as well
Again, tb$": )" works just as well as tb$': )'
So are they effectively interchangeable?
Interestingly, when I plot a graph
annoying <- tibble(
`1` = 1:10,
`2` = `1` * 2 + rnorm(length(`1`))
)
ggplot(annoying, aes(x = `1`, y = `2`)) +
geom_point()
Single quotes must be used when referring to the nonsyntactic variables because otherwise, it looks like ggplot treats X and Y as single points of 1 and 2 respectively. Are there any other cases like this?
It's important to distinguish between single quotes (') and backticks (or "back-single-quotes") (`).
Most of what you want to know is in ?Quotes:
Single (') and double (") quotes delimit character constants. They can be
used interchangeably but double quotes are preferred (and
character constants are printed using double quotes), so single
quotes are normally only used to delimit character constants
containing double quotes.
Almost always, other [i.e., non-syntactically valid] names can be used
provided they are quoted. The preferred quote is the backtick
(‘`’) ... under many
circumstances single or double quotes can be used (as a character
constant will often be converted to a name). One place where
backticks may be essential is to delimit variable names in
formulae: see ‘formula’.
For example, if you want to define a variable name containing a space, you need back-ticks:
`a b` <- 1
Double quotes also work here (to my surprise!)
"a b" <- 1
but if you want to use the resulting variable in an expression you'll need to use back-ticks. "a b" + 1 gives an error (" non-numeric argument to binary operator") but `a b`+1 works.
As #r2evans points out, the same rules apply in tidyverse expressions. You can use double- or single-quotes (if you want) to define new variables: mtcars %>% mutate("my stuff"=4), but if you want to subsequently use that variable (or any other non-syntactic variable) in an expression, you have to backtick-protect it: mtcars %>% mutate("my stuff"=4, new=`my stuff` + 5).
It's probably best practice/least confusing to just use backticks for all non-syntactic variable reference and single quotes for character constants.
DEFINE VARIABLE a AS CHARACTER NO-UNDO.
DEFINE VARIABLE b AS CHARACTER NO-UNDO.
a = "123".
b = "123 ".
MESSAGE a = b
VIEW-AS ALERT-BOX.
MESSAGE LENGTH(a) = LENGTH(b)
VIEW-AS ALERT-BOX.
Does anyone know, why the first equals returns true?
Are whitespaces ignored on the right side? Because a whitespace on the left would cause the equals to be false. It also doesn't matter how many whitespaces there are on the right side.
Thank you all
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/eq-or-=-operator.html
The equal comparison ignores trailing blanks. Thus, "abc" is equal to "abc ". However, leading and embedded blanks are treated as characters and " abc" is not equal to "abc".
Well, that's just the way the ABL is implemented.
You can use the COMPARE function.
MESSAGE a = b SKIP
COMPARE (a, "EQ", b, "RAW")
VIEW-AS ALERT-BOX.
How to create a sequence starting with a character and then with numbers in R
I wanna to create a sequence like the following:
y1998 y1999 y2000 till y2011
There's ::
1998:2011
And ' or " to create string constants:
'y'
And paste0 to concatenate both:
paste0('y', 1998:2011)
Note how the paste0 function is applied to the second parameter, element by element. That's one of R's strengths.
I have string value in that I need to convert to double in VB.Net. Conditions are like below
string = "12345.00232232"
if condition is 3 (2 digits after decimal and comma)
display = 12,345.00
if condition is 5 (5 digits after decimal and comma)
display = 12,345.00232
If Condition is 7 ( 5 digits after decimal and no comma)
display = 12345.00232
How can I do that in VB.Net?
It sounds like you want to take a numeric input, convert it to double but then reformat it as a string based upon a numeric value for a specific style. Something probably like...
Public Function FormatNumericString(ByVal input As String, ByVal style As Integer) As String
Dim result As String = String.Empty
Dim temp As Double = Double.Parse(input) 'will throw on invalid input
Select Case style
Case 3
result = temp.ToString("#,##0.00")
Case 5
result = temp.ToString("#,##0.00000")
Case 7
result = temp.ToString("0.00000")
End Select
Return result
End Function
The basic thing is you have to convert the string to a double and use whatever formatting style you want. I've chosen to use double.Parse so that an exception would be thrown on an invalid input. double.TryParse could also be used, but it returns a true/false value rather than throwing an exception on an invalid input. It depends upon the behavior you want to follow.
We are currently having an issue due to implicit conversion in an IF statement in VBScript (Classic ASP) that don't do implicit conversion the same way when dealing with a variable or a literal. Can someone explain this behavior to me, why do VBScript acts this way ?
Here is a sample of what I mean :
Const c_test = 3
Dim iId : iId = 3
Dim iTestStr : iTestStr = "3"
If iId = iTestStr Then
Response.Write("Long variable = String variable : Equal")
Else
Response.Write("Long variable = String variable : Not Equal")
End If
Response.Write("<br/>")
If c_test = iTestStr Then
Response.Write("Long constant = String variable : Equal")
Else
Response.Write("Long constant = String variable : Not Equal")
End If
Response.Write("<br/>")
If c_test = iId Then
Response.Write("Long constant = Long variable : Equal")
Else
Response.Write("Long constant = Long variable : Not Equal")
End If
Response.Write("<br/>")
If iId = "3" Then
Response.Write("Long variable = String literal : Equal")
Else
Response.Write("Long variable = String literal : Not Equal")
End If
Response.Write("<br/>")
If c_test = "3" Then
Response.Write("Long constant = String literal : Equal")
Else
Response.Write("Long constant = String literal : Not Equal")
End If
Which ouputs :
Long variable = String variable : Not Equal
Long constant = String variable : Not Equal
Long constant = Long variable : Equal
Long variable = String literal : Equal
Long constant = String literal : Equal
Which is quite confusing o_O
This is the result of one documented behavior and one undocumented one.
The documented behavior is that in comparisons, a number is always less than a string. This is mentioned in the documentation for Comparison Operators. Paraphrasing the table near the bottom of the page:
If one expression is numeric and the other is a string, then the numeric expression is less than the string expression.
The undocumented behavior is that comparisons involving literals are handled differently from comparisons involving variables. See this blog entry for more details. To summarize the important conclusion:
The relevant comparison rules in VB6/VBScript go like this:
Hard string ~ hard number: convert string to number, compare numbers
Hard string ~ soft number: convert number to string, compare strings
Soft string ~ hard number: convert string to number, compare numbers
Soft string ~ soft number: any string is greater than any number
The documented behavior explains why the first two comparisons are false, while the undocumented behavior explains why the last two comparisons are true.
You are (implicitly) declaring your variables As Variant so your If conditions actually test the equality of two Variants and determine that they are unequal.
In the last cases, however, you are using String constants (which can never be Variant, even if declared without a type) and String literals.
My guess is that when you compare two Variants, VB first determines whether they have the same type tag and if they don’t, resolves to False.