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.

Zahlen aus String extrahieren

Empfohlene Antworten

Veröffentlicht

Hi!

Also, ich habe eine Zeichenfolge, z. B. "ope39m8zy1" und möchte nun die Zahlen daraus extrahieren.

Wie geht sowas :confused: ?

Ich hoffe, mir kann da jemand helfen...

Gruß,

Technician

Hier eine Lösung in Visual Basic:

---------------------------

Dim strLength As Integer

Dim i As Integer

Dim dein_string

Dim dummy As String

Dim result As String

dein_string = Text1.Text

strLength = Len(dein_string) 'Länge wird überprüft

For i = 1 To strLength

dummy = Mid(dein_string, i, 1)

If IsNumeric(dummy) Then

'IsNumeric fragt ab ob es sich um einen Integerwert handelt, Rückgabewert true/false

result = result & dummy

End If

Next i

-----

Hier wird ein String aus einer Textbox "Text1" ausgelesen und durchgeparst.

Das Ergebnis wird nach und nach in einen String geschrieben (kannst auch Optional in ein Array schreiben, oder an der Stelle eine Function aufrufen die mit dem Integer weiterarbeitet).

Bitte schreib das nächste mal dazu in welcher Sprache ...

Hat bei mir funktioniert, probiers mal aus ;)

Gruß,

Spike

[ 07. Juni 2001: Beitrag editiert von: Spike ]

@Spike

Stimmt, ich hab' vergessen, dazuzuschreiben, dass es um VB geht...

Danke für deine Hilfe; ich hatte dann aber zwischenzeitlich doch noch einen Einfall ;)

Etwas anderer Ansatz:

--

Private Sub Command1_Click()

Dim i As Integer

Dim s As String

Dim strRes As String

s = Text1.Text

For i = 1 To Len(s)

If Asc(Mid(s, i, 1)) >= 48 And Asc(Mid(s, i, 1)) <= 57 Then

strRes = strRes & Mid(s, i, 1)

End If

Next i

Text2.Text = strRes

End Sub

--

Gruß,

Technician

Ja, so wollte ich es zuerst auch machen ...

Mit der Funktion IsNumeric kannst du aber auch später überprüfen ob es ein gültiger float ist, falls das mal später als Anforderung kommt.

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.