Veröffentlicht 23. Januar 200619 j Hallo, neues Problem, wie kann ich aus einem String einen anderen String entfernen ? ich hab es mit Replace versucht, aber das scheint nicht so ganz zu funktionieren also: str1 = "abcdef" str2 = "bcd" str3 = remove(str1, str2) //"aef" funktionen dazu find ich irgentwie nicht
23. Januar 200619 j Public Function ReplaceCharacters(ByRef strText As String, _ ByRef strUnwanted As String, ByRef strRepl As String) _ As String Dim i As Integer Dim ch As String For i = 1 To Len(strUnwanted) ' Replace the i-th unwanted character. strText = Replace(strText, Mid$(strUnwanted, i, 1), _ strRepl) Next ReplaceCharacters = strText End Function Sub MyTest() Dim str1 As String Dim str2 As String str1 = "abcdef" str2 = "bcd" 'str3 = Remove(str1, str2) '"aef" 'geht nicht, woher auch, was ist Remove? str3 = ReplaceCharacters(str1, str2, "") 'geht [/code] s'Amstel
24. Januar 200619 j oder für die codesparer (und unsaubereren programmierer): Sub dfsdf() das = "XYABCDE" das = Replace(das, "ABC", "") 'erjebnis XYDE End Sub[/PHP]
24. Januar 200619 j Autor ist das nicht das gleiche wie vom Amstelchen? naja... hab mir jetzt selbst nen Konstrukt zusammen gebastelt: Private Function Remove(ByVal strText, ByVal strString) As String On Error GoTo ErrorMessage Dim nPosL, nPosR As Long While (Not (InStr(0, strText, strString, 0) = 0)) nPosL = InStr(0, strText, strString, 0) - 1 nPosR = nPosL + Len(strString) + 1 strText = Left(strText, nPosL) & Right(strText, nPosR) Wend Remove = strText Exit Function ErrorMessage: MsgBox prompt:=Err.Description, buttons:=vbOKOnly, Title:="Fehler: " & CStr(Err.Number) End Function Da hab ich endlich mein Remove
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.