Techno1
(Techno1)
October 31, 2023, 10:45am
1
Hi,
I have a String with value = 1.241.82
I want to replace only the first period (.) in the string with comma (,).
The first period can come anywhere in the string (like 12.41.82 or 124.1.82)
The index of the first period is dynamic.
I tried the below approach, but it did not work.
Any suggestion would be helpful
Thanks
Hi @Techno1
please go throuh the below image
variable “idx” is of type int32
Anil_G
(Anil Gorthi)
October 31, 2023, 10:59am
3
@Techno1
Please try this
str.Substring(0,str.IndexOf(".")) + "," + str.Substring(str.IndexOf(".")+1)
here str is the string variable where the original string is stored
Hope this helps
cheers
Parvathy
(PS Parvathy)
October 31, 2023, 11:04am
4
Hi @Techno1
Try this:
Input="1.241.82"
Output= Input.Substring(0, Input.IndexOf(".")) & "," & Input.Substring(Input.IndexOf(".") + 1)
Input="12.41.82"
Output= Input.Substring(0, Input.IndexOf(".")) & "," & Input.Substring(Input.IndexOf(".") + 1)
Hope it helps!!
Techno1:
1.241.82
Hi @Techno1 ,
Could check with the below as well :
(new Regex("\.")).Replace("1.241.82",",",1)
Yoichi
(Yoichi)
October 31, 2023, 1:24pm
7
Hi,
FYI, another approach using Microsoft.VisualBasic.Strings.Replace:
Strings.Replace(yourString,".",",",1,1)
Regards,
1 Like