Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

String aus einem String entfernen

Empfohlene Antworten

Veröffentlicht

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 :(

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

oder für die codesparer (und unsaubereren programmierer):

Sub dfsdf()
das = "XYABCDE"
das = Replace(das, "ABC", "") 'erjebnis XYDE
End Sub[/PHP]

  • 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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.