Nh123
Nh123

Reputation: 1017

Remove string 1 time from other string

my string is for example : 111

i want to remove 1 from my string

result:

11

what i have tried:

Replace(string, "1", "")

result : Null

Upvotes: 0

Views: 107

Answers (4)

NeverHopeless
NeverHopeless

Reputation: 11233

I guess there are several ways to do so.

Two of them are: (Use RIGHT method)

    Dim s As String = "1111"
    Dim newstring1 As String = Strings.Right(s, s.Length - 1)

and: (Use substring method)

    Dim s As String = "1111"
    Dim newstring2 As String = s.Substring(1)

But make sure to check length of string to avoid getting ArgumentException.

Upvotes: 0

AlwaysBTryin
AlwaysBTryin

Reputation: 1964

Replace has a Count parameter, which says how many times to do the string replacement. So what you want is:

Replace(string, "1", "", 1, 1)

http://msdn.microsoft.com/en-US/library/bt3szac5(v=VS.80).aspx

Upvotes: 0

gahooa
gahooa

Reputation: 137352

Look at the Count argument to the Replace() function.

http://msdn.microsoft.com/en-us/library/bt3szac5(v=vs.80).aspx

Replace("11111", "1", "", , 1)

It allows you to limit the number of replacements.

Upvotes: 3

famf
famf

Reputation: 2233

try this:

Replace(yourstring, "1", "", , 1)

Upvotes: 2

Related Questions