Removing the first numbers in a string


Hi Im trying to remove the 1st 2 numbers in my list but i cant seem to make it work i always get a null value whenever i use a substring(0, str-2) function i even tried remove but what it removes is the last 2 digits of my numbers my sample number is 0420 and i want to remove the 04 and get the 20.

Help is greatly appreciated I have been stuck in this problem since 2days ago.


Hey @Arvin_Gabriel_Mari_A

You can do this with String.Remove().

String str_data= "0420";
String new_data = str_data.Remove(0,2) 



HI @Arvin_Gabriel_Mari_A,
You can go by @aksh1yadav’s solution if you want to remove.
Else you can try with the sub string as follows:

It will give you the result excluding the first two characters/numbers.
Hope it helps.


Hello, I have a similar requirement. I am reading (1,00) such value into a variable and i want to use only 1 out of the string and ignore the zeroes. how can i use Sub-string in this case?

Thanks !!



Split based on colum and get the first element

str B= stra.Split({","},StringSplitOptions.RemoveEmptyEntries).ToList()(0).ToString



Hi @Maverick,

Convert the number into string and follow this method.

Substring helpes here…

It will be successful even if you remove comma from the entire number.



Thanks, this is working like i wanted !!


Hi Mahesh,
your solution is more flexible,as it is working with all values. thanks !!
I need to do a summation of this column, containing comma values like… 1,00 2,00 10,00 etc. Comma represents decimal notation so i need to ignore the zeroes and consider only preceeding value. I tried using “Compute(SUM(columnname)” but it won’t work… how can i alter the values in datatable itself and do the summation?



Try this

Declare a variable with type double Sum

Sum=dt.AsEnumerable.Sum(Function(row) Convert.ToDouble(row(“Column_Name”).ToString.Split({","},stringSplitOptions.RemoveEmptyEntries)(0)))