DineshChauhan
DineshChauhan

Reputation: 121

Remove dot between two strings

Is there any way to remove dot between two string?

I have two string: Linkw2.ID and Linkw2.t169ID.

I want these to be Linkw2ID, Linkw2t169ID.

I was using string substring = InpParam.Substring(0, InpParam.IndexOf(".")); but it will return me Linkw2 and Linkw2.

Upvotes: 2

Views: 201

Answers (3)

karimvai
karimvai

Reputation: 319

String str="Linkw2.ID";
String str1=str.Replace(".","");

This creates new string str1 with dots removed from str.

Or else

str=str.Replace(".","");

This creates a new string with dots removed from str and updates str with the result.

Upvotes: 1

Adil
Adil

Reputation: 148160

You can use String.Replace to remove the dot with empty string. Do not forget to assign the result back to string if you want to change the value.

This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of oldValue are replaced by newValue, MSDN.

str = str.Replace(".", "");

Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string, MSDN

Upvotes: 6

csteinmueller
csteinmueller

Reputation: 2487

Try

substring = InParam.Replace(".","");

Or you use

var sub = InpParam.Substring(0, InpParam.IndexOf(".")) +
                  InpParam.Substring(InpParam.IndexOf(".") + 1, InpParam.Length - InpParam.IndexOf(".") - 1);

Upvotes: 1

Related Questions