Removing the first numbers in a string


#1

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.


#2

Hey @Arvin_Gabriel_Mari_A

You can do this with String.Remove().

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

Regards…!!
Aksh


#3

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.
Regards,
Jiban


#4

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 !!


#5

@Maverick

Split based on colum and get the first element
stra=1,00

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

Regards,
Mahesh


#6

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.
image

Thanks,
Jiban


#7

Thanks, this is working like i wanted !!


#8

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?


#9

@Maverick

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)))

Regards,
Mahesh