View Full Version : [SOLVED:] Part of a string
ksilenio
10-28-2019, 09:29 AM
Hi to every one . I'd like to ask how can get a part of a string .Example: I have a string "StrA/Strb", now how can i get the part before the slash, or after the slash "StrB". Thank you for your time Regards
Leith Ross
10-28-2019, 09:48 AM
Hello Ksilenio,
In VBA you would the Split function. This will return an zero based array (1-D) of the strings. You can specify the delimiter. The default is a comma.
Sub SplitStrings()
Dim n As Long
Dim Text As string
Dim vArray As Variant
Text = "StrA/StrB"
vArray = Split(Text, "/")
Text = ""
For n = 0 To UBound(vArray) - 1
Text = Text & vArray(n) & vbLf
Next n
MsgBox Text
End Sub
Paul_Hossler
10-28-2019, 09:49 AM
VBA way
Option Explicit
Sub test()
Dim v As Variant
Dim s As String
s = "StrA/StrB"
v = Split(s, "/")
MsgBox v(0) ' starts at 0
MsgBox v(1)
End Sub
ksilenio
10-28-2019, 10:11 AM
Thank you Leith ,but, can you explain me
1. what does it mean "vbLf" and
2. how to get the string after the slash
Regards
Leith Ross
10-28-2019, 10:51 AM
The vbLf is a string constant for the Line Feed character Chr(10). See Paul's post for breaking down individual strings.
ksilenio
10-28-2019, 11:11 AM
Hi Paul , thank you for your answer but how get the string after the slash ,mean "StrB"
Ok I found it Paul .Thank you Paul
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.