2011-03-22 7 views
15

나는이 문자열이 : 나는 제거하는 기능을 원하는VB.NET 문자열에서 문자를 제거

Dim stringToCleanUp As String = "bon;jour" 
Dim characterToRemove As String = ";" 

을 ';' 다음과 같은 문자 :

Function RemoveCharacter(ByVal stringToCleanUp, ByVal characterToRemove) 
... 
End Function 

기능은 무엇입니까?

답변 :

Dim cleanString As String = Replace(stringToCleanUp, characterToRemove, "") 

좋아요, 감사합니다!

+0

Visual Basic 및 VB.NET은 같은 것이 아니다 ("문자로 대체 할", "문자을 제거 할") (Visual Basic의 비는 .NET 언어). – Oded

+0

이 두 제품의 차이점은 무엇입니까? –

+2

기본적으로 네이티브'string.replace'를 감싸고 있다는 것을 깨닫게 될 다음 개발자를 생각해보십시오. 즉, 필요하지 않을 때 더 많은 추상화를 추가하십시오. 옆으로 : 당신은 녹색 체크 표시로 대답을 '수락'으로 표시해야합니다. –

답변

7
Function RemoveCharacter(ByVal stringToCleanUp, ByVal characterToRemove) 
    ' replace the target with nothing 
    ' Replace() returns a new String and does not modify the current one 
    Return stringToCleanUp.Replace(characterToRemove, "") 
End Function 

여기에 대한 VB's Replace function

16

String 클래스에는이를 수행하는 Replace 메서드가 있습니다.

Dim clean as String 
clean = myString.Replace(",", "") 
4

string 클래스의 Replace 방법은 또한 문자열에서 여러 문자를 제거 할 수 있습니다 자세한 내용은 다음과 같습니다

Dim newstring As String 
newstring = oldstring.Replace(",", "").Replace(";", "") 
0

당신은 문자열을 사용할 수에게 .replace 메서드

문자열 .replace

Dim strName As String 
strName.Replace("[", "") 
관련 문제