I have a problem, I need to know how I can detect if a value has a zero at the beginning
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
variable = 01
turn it to 1
I guess what you are trying to say is that you want to eliminate the “0” at the beginning of the integer variable.
Output - 2
input - 03456
output - 3456
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,
You can read this article to address your issue.
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:
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”, “”)
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”
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
Please try using variable.TrimStart("0"c)
This will trim any leading 0s from the value.
if you only need the number without “0” on the left you only have to make a convertion to double or int like this =
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
Here’s a solution for removing leading zeroes with regular expressions.
All leading zeroes
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.