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

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

Related

Remove characters which repeat more than twice in a string [duplicate]

This question already has answers here:
remove repeated character between words
(4 answers)
Closed 3 years ago.
I have this text:
F <- "hhhappy birthhhhhhdayyy"
and I want to remove the repeat characters, I tried this code
https://stackoverflow.com/a/11165145/10718214
and it works, but I need to remove repeat characters if it repeats more than 2, and if it repeated 2 times keep it.
so the output that I expect is
"happy birthday"
any help?
Try using sub, with the pattern (.)\\1{2,}:
F <- ("hhhappy birthhhhhhdayyy")
gsub("(.)\\1{2,}", "\\1", F)
[1] "happy birthday"
Explanation of regex:
(.) match and capture any single character
\\1{2,} then match the same character two or more times
We replace with just the single matching character. The quantity \\1 represents the first capture group in sub.

Need to extract only those digits which are having 5 to 6 digit length [duplicate]

This question already has answers here:
How to use grep()/gsub() to find exact match
(2 answers)
Closed 4 years ago.
I need to extract only 5 or 6 digit from a string. For example "hi 23456678 is number, also there is a number 92844 and 741653 "
I need to extract only the 5 or 6 digit number from string , i tried \d{5,6} but it is giving me result as (23456, 92844, 741653) but my desired outcome should be only 92844 & 741653 , how can i get that.
I am using R, please suggest.
You can try this
^[0-9]{5,6}$
{5,6} = between 5 and 6 characters

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

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.

Remove a part of a string [duplicate]

This question already has answers here:
Remove part of string after "."
(6 answers)
Closed 5 years ago.
I got a string;
"Enviroment is dangerous.123"
Now I want to remove everything after "dangerous" so the result will be
"Enviroment is dangerous"
I got different text strings of different length. So it needs to respond to the string "dangerous"
How do I do that?
We can use sub to match the . followed by one or more numbers (\\d+) until the end of the string ($) and replace with blank ("")
sub("\\.\\d+$", "", str1)
#[1] "Enviroment is dangerous"
data
str1 <- "Enviroment is dangerous.123"

get first part of a string in R [duplicate]

This question already has answers here:
Extract part of string before the first semicolon
(4 answers)
Closed 7 years ago.
I have a string "00_123.txt". I want to get first part of the string before ".", that is simply "00_123"
I found the substring("00_123.txt", 0, stop) can do it. But the problem is that I don't know where to stop, because the length of "00_123" can be changed.
How can I do that?
x <- "00_123.txt"
gsub("\\..*$", "", x)
[1] "00_123"

Resources