kisoft Well-Known Member Licensed User Longtime User Dec 7, 2018 #1 Hi How to divide a string into parts using this class? https://www.b4x.com/android/forum/t...uilder-for-regular-expressions.83495/#content For example: Code: Copy dim str as string= "aaa.bbb.ccc" dim a,b,c as string 'I would like to get three variables a = aaa b = bbb c = ccc
Hi How to divide a string into parts using this class? https://www.b4x.com/android/forum/t...uilder-for-regular-expressions.83495/#content For example: Code: Copy dim str as string= "aaa.bbb.ccc" dim a,b,c as string 'I would like to get three variables a = aaa b = bbb c = ccc
udg Expert Licensed User Longtime User Dec 7, 2018 #2 In that simple case you can just copy&paste code from the Splitting section of this tutorial by Erel: https://www.b4x.com/android/forum/threads/b4x-regular-expressions-regex-tutorial.7123/#content Upvote 0
In that simple case you can just copy&paste code from the Splitting section of this tutorial by Erel: https://www.b4x.com/android/forum/threads/b4x-regular-expressions-regex-tutorial.7123/#content
kisoft Well-Known Member Licensed User Longtime User Dec 7, 2018 #3 Thank you for your response. I know this can be done for example: Code: Copy dim a,b,c as string Dim data As String data = "aaa.bbb.ccc Dim numbers() As String numbers = Regex.Split("\.", data) Dim l As List l.Initialize2(numbers) a=l.Get(0) b=l.Get(1) c=l.Get(2) is it possible to do this with this class? https://www.b4x.com/android/forum/t...uilder-for-regular-expressions.83495/#content it divides the string into parts but I would like to assign them to variables a, b, c Code: Copy dim a,b,c as string dim str as string= "aaa.bbb.ccc'' Dim rx As RegexBuilder For Each s As String In Regex.Split(rx.Initialize.AppendEscaped(".").Pattern, str ) Log(s) Next Last edited: Dec 7, 2018 Upvote 0
Thank you for your response. I know this can be done for example: Code: Copy dim a,b,c as string Dim data As String data = "aaa.bbb.ccc Dim numbers() As String numbers = Regex.Split("\.", data) Dim l As List l.Initialize2(numbers) a=l.Get(0) b=l.Get(1) c=l.Get(2) is it possible to do this with this class? https://www.b4x.com/android/forum/t...uilder-for-regular-expressions.83495/#content it divides the string into parts but I would like to assign them to variables a, b, c Code: Copy dim a,b,c as string dim str as string= "aaa.bbb.ccc'' Dim rx As RegexBuilder For Each s As String In Regex.Split(rx.Initialize.AppendEscaped(".").Pattern, str ) Log(s) Next
S sorex Expert Licensed User Longtime User Dec 7, 2018 #4 you probably end up with more code than your example above it unless you store them in an array/list/map. by the way... that list is not even needed so you can remove 2 lines there and use a=numbers(0) instead. Upvote 0
you probably end up with more code than your example above it unless you store them in an array/list/map. by the way... that list is not even needed so you can remove 2 lines there and use a=numbers(0) instead.
Erel B4X founder Staff member Licensed User Longtime User Dec 9, 2018 #5 The purpose of RegexBuilder is to help you build the pattern. Once you got the pattern you use the regular Regex methods. Code: Copy Dim a,b,c As String Dim data As String = "aaa.bbb.ccc" Dim builder As RegexBuilder Dim numbers() As String = Regex.Split(builder.Initialize.AppendEscaped(".").Pattern, data) Dim l As List l.Initialize2(numbers) a=l.Get(0) b=l.Get(1) c=l.Get(2) Upvote 0
The purpose of RegexBuilder is to help you build the pattern. Once you got the pattern you use the regular Regex methods. Code: Copy Dim a,b,c As String Dim data As String = "aaa.bbb.ccc" Dim builder As RegexBuilder Dim numbers() As String = Regex.Split(builder.Initialize.AppendEscaped(".").Pattern, data) Dim l As List l.Initialize2(numbers) a=l.Get(0) b=l.Get(1) c=l.Get(2)
M Mahares Expert Licensed User Longtime User Dec 9, 2018 #7 Erel said: Dim a,b,c As String Dim data As String = "aaa.bbb.ccc" Dim builder As RegexBuilder Dim numbers() As String = Regex.Split(builder.Initialize.AppendEscaped(".").Pattern, data) Dim l As List l.Initialize2(numbers) a=l.Get(0) b=l.Get(1) c=l.Get(2) Click to expand... Why do you insist on using a list in this case when: Code: Copy a=numbers(0) b=numbers(1) c=numbers(2) and uses fewer lines of code. Upvote 0
Erel said: Dim a,b,c As String Dim data As String = "aaa.bbb.ccc" Dim builder As RegexBuilder Dim numbers() As String = Regex.Split(builder.Initialize.AppendEscaped(".").Pattern, data) Dim l As List l.Initialize2(numbers) a=l.Get(0) b=l.Get(1) c=l.Get(2) Click to expand... Why do you insist on using a list in this case when: Code: Copy a=numbers(0) b=numbers(1) c=numbers(2) and uses fewer lines of code.
Erel B4X founder Staff member Licensed User Longtime User Dec 9, 2018 #8 There is actually never any good reason to use List.Initialize2. It is equivalent to: Code: Copy Dim l As List = numbers Upvote 0
There is actually never any good reason to use List.Initialize2. It is equivalent to: Code: Copy Dim l As List = numbers