borismh
(Boris)
March 2, 2020, 6:34am
1
Hi everyone
I have a problem, I need to know how I can detect if a value has a zero at the beginning
example:
variable = 1
and since it doesn’t have a zero at the beginning, I need
note = string variable
and I also want it to be vice versa for other cases
example:
variable = 01
turn it to 1
1 Like
hacky
(NotHacker)
March 2, 2020, 6:40am
2
@borismh
I guess what you are trying to say is that you want to eliminate the “0” at the beginning of the integer variable.
eg:-
input- 02
Output - 2
input - 03456
output - 3456
input- 00004
output - 4
Please confirm and let me know if this is what you want.
If above is the case, all you can do is:-
string input_variable = 093
int Result = Cint(input_variable)
If you try printing the value of the variable Result in the message box, you will get the value 93.
Thanks and Regards,
@hacky
2 Likes
Hi @borismh
You can read this article to address your issue.
Hi,
if you are a beginner in the world of automation and would like to know how you can manipulate text based on the solutions available in the VB.NET code and using REGEX (regular expressions) then you are in the right place.
In the topic below, you will learn how to easily extract data from any part of the search text using various methods.
The topic includes solution examples with descriptions and graphics to better understand the topic for functions such as:
Split
Substring
Left
Right
R…
cheers
Happy learning
6 Likes
borismh
(Boris)
March 2, 2020, 6:43am
4
@hacky
if I want to detect first if it has a zero at the beginning of the variable and from that point delete it or create a zero at the beginning
@borismh , If I understood correctly, you want to delete “0” from string and return the result. If so you can use replace method.
e.g. stringVariableName = stringVariableName.Replace(“0”, “”)
1 Like
borismh
(Boris)
March 2, 2020, 12:25pm
6
@Bhavik_Solanki
ok, but to detect if it has a zero at the beginning, since this would be my conditioner
@borismh , if you are ok with first character you can use substring method.
E.g. stringVariableName.Substring(0,1) = “0”
1 Like
borismh
(Boris)
March 2, 2020, 1:09pm
8
@Bhavik_Solanki
ready until that part is done, but now I just want to add 0 to variables that are only from 1 to 9, there is some way thank you very much
SowmyaLeo
(Sowmya Sivakumar)
March 2, 2020, 2:18pm
9
@borismh
Please try using variable.TrimStart("0"c)
This will trim any leading 0s from the value.
2 Likes
if you only need the number without “0” on the left you only have to make a convertion to double or int like this =
variable1= Cint(“01”)
now variable1 will be equal to 1 and you can convert it to string again
strVariable = variable1.toString()
Now you can continue doing whatever you want with it
1 Like
Here’s a solution for removing leading zeroes with regular expressions.
One zero
System.IO.RegularExpressions.Regex.Replace("^0", String.Empty)
All leading zeroes
System.IO.RegularExpressions.Regex.Replace("^0+", String.Empty)
3 Likes
system
(system)
Closed
March 5, 2020, 7:25pm
12
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.