How to convert A0058 value to 9958 in progress 4gl [duplicate] - openedge

This question already has answers here:
How to convert A00073 value to 9973 in progress 4gl
(5 answers)
Closed 5 years ago.
i have column having multiple value like A0045 ,A00065 . i want to convert it 9945, 9965. Need to remove all 0 and character value and add 99 before that value..
replace(val,"A","99") will replace only A I want to go for A-Z occurrence.. Any char should be convert .. Please help

How about
newValue = "99" + LEFT-TRIM( oldValue, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ).
This should take all leading alpha and zero characters from the string, and prefix with 99.

/************Try this*********************/
define variable word as character no-undo.
define variable i as integer no-undo.
assign word = "A00065".
/******to remove all the zeroes**************/
word = replace(word,substring(word,index(word,"0"),(r-index(word,"0") - 1)),"").
do i = 65 to 90:
if substring(word,1,1) = chr(i) then
do:
word = replace(word,substring(word,1,1),"99").
leave.
end.
end.
display word.

Related

Remove first character of string with condition in R [duplicate]

This question already has answers here:
remove leading 0s with stringr in R
(3 answers)
Closed 2 years ago.
I'm trying to remove the 0 that appears at the beginning of some observations for Zipcode in the following table:
I think the sub function is probably my best choice but I only want to do the replacement for observations that begin with 0, not all observations like the following does:
data_individual$Zipcode <-sub(".", "", data_individual$Zipcode)
Is there a way to condition this so it only removes the first character if the Zipcode starts with 0? Maybe grepl for those that begin with 0 and generate a dummy variable to use?
We can specify the ^0+ as pattern i.e. one or more 0s at the start (^) of the string instead of . (. in regex matches any character)
data_individual$Zipcode <- sub("^0+", "", data_individual$Zipcode)
Or with tidyverse
library(stringr)
data_individual$Zipcode <- str_remove(data_individual$Zipcode, "^0+")
Another option without regex would be to convert to numeric as numeric values doesn't support prefix 0 (assuming all zipcodes include only digits)
data_individual$Zipcode <- as.numeric(data_individual$Zipcode)

Match string between ; and % [duplicate]

This question already has answers here:
Extracting a string between other two strings in R
(4 answers)
Closed 2 years ago.
I wish to extract the decimal value in the string without the % sign. So in this case, I want the numeric 0.45
x <- "document.write(GIC_annual[\"12-17 MTH\"][\"99999.99\"]);0.450%"
str_extract(x, "^;[0-9.]")
My attempt fails. Here's my thinking.
Begin the extraction at the semicolon ^;
Grab any numbers between 0 and 9.
Include the decimal point
You also have this option:
stringr::str_extract(y, "\\d\\.\\d{1,}(?=%)")
[1] "0.450"
So basically you look ahead and check if there is % or not, if yes, you capture the digits before it.
Details
\\d digit;
\\. dot;
\\d digit;
{1,} capturing 1 or more digit after .;
(?=%) look ahead and check if there is % and if there is one, it retuns captured number
Since you don't want semi-colon in the output use it as lookbehind regex.
stringr::str_extract(x, "(?<=;)[0-9]\\.[0-9]+")
#[1] "0.450"
In base R using sub :
sub('.*;([0-9]\\.[0-9]+).*', '\\1', x)

Regex for "is every character in string numeric?" [duplicate]

This question already has answers here:
Regex to check whether a string contains only numbers [duplicate]
(21 answers)
Check if string contains ONLY NUMBERS or ONLY CHARACTERS (R)
(3 answers)
Closed 4 years ago.
I'm wondering what regex pattern I could use to detect if every character in a string is numeric.
So, here's what I'm thinking that isn't working:
stringr::str_detect("311apple", "[0-9]")
#> [1] TRUE
That statement is TRUE because there exists a numeric character in that string, but I'm trying to find a pattern so that it's only TRUE if every character is numeric.
Any ideas? Thanks!

How to read Cell if it has two dashes (-) in it? [duplicate]

This question already has answers here:
Count specific character occurrences in a string
(26 answers)
Closed 6 years ago.
I am trying to read the cell and see if the invoice number has two dashes (-).
So for example:
4-2949493
4-9390023-1
If (e.Row.RowType = DataControlRowType.DataRow) Then
If (e.Row.Cells(1).Text.ToString = (TWO DASHES) Then
Else
End If
End If
How would I check to see if it has two dashes? The invoice length changes every time too.
Carl,
Take the string text from the cell and loop through the characters counting the occurrences of the desired character:
Dim charCount as integer = 0
For each c as char in e.rows.cells(1).text.tostring.toCharArray
If c = "-" then
charCount += 1
End If
Next

Remove underscore from a string in R [duplicate]

This question already has answers here:
Replace specific characters within strings
(7 answers)
Closed 7 years ago.
In my data.frame, I have a column of type character, where all the values look like this : 123_456 (three digits, an underscore, three digits).
I need to transform these values to a numeric, and as.numeric(my_dataframe$my_column) gives me a NA. Therefore I need to remove the underscore first, in order to do as.numeric.
How would I do that please ?
Thanks
We can use sub
as.numeric(sub("_", "", my_dataframe$my_column))

Resources