Mashiane Expert Licensed User Longtime User Aug 2, 2019 #1 Hi there Let's assume, this is the master content.. Code: Copy Today #I# got to #experiment# #with# reef. I #needed# this to try #and# see if #I# can #wrap# it with #BANano#.png Now I need to return a list that will have Code: Copy I,experiment,with,needed,and,wrap,BANano And kindly need a code snippet for such. Preferably not RegEx please. Thanks
Hi there Let's assume, this is the master content.. Code: Copy Today #I# got to #experiment# #with# reef. I #needed# this to try #and# see if #I# can #wrap# it with #BANano#.png Now I need to return a list that will have Code: Copy I,experiment,with,needed,and,wrap,BANano And kindly need a code snippet for such. Preferably not RegEx please. Thanks
E emexes Expert Licensed User Longtime User Aug 2, 2019 #2 Mashiane said: Preferably not RegEx please. Click to expand... I know you thought you'd never hear these words from me, but: this is probably better done with regex :-/ Nonetheless... try this: Code: Copy Dim L As List L.Initialize Dim S As String = "Today #I# got to #experiment# #with# reef. I #needed# this to try #and# see if #I# can #wrap# it with #BANano#.png" Dim OpenHashAt As Int = -1 For I = 0 To S.Length - 1 If S.CharAt(I) = "#" Then If OpenHashAt = -1 Then 'if not currently inside a hash field OpenHashAt = I Else 'currently inside a hash field L.Add(S.SubString2(OpenHashAt + 1, I)) OpenHashAt = -1 'now outside of hash field, get ready for next one End If End If Next I Last edited: Aug 2, 2019 Upvote 0
Mashiane said: Preferably not RegEx please. Click to expand... I know you thought you'd never hear these words from me, but: this is probably better done with regex :-/ Nonetheless... try this: Code: Copy Dim L As List L.Initialize Dim S As String = "Today #I# got to #experiment# #with# reef. I #needed# this to try #and# see if #I# can #wrap# it with #BANano#.png" Dim OpenHashAt As Int = -1 For I = 0 To S.Length - 1 If S.CharAt(I) = "#" Then If OpenHashAt = -1 Then 'if not currently inside a hash field OpenHashAt = I Else 'currently inside a hash field L.Add(S.SubString2(OpenHashAt + 1, I)) OpenHashAt = -1 'now outside of hash field, get ready for next one End If End If Next I
vpires Member Licensed User Longtime User Aug 2, 2019 #3 Well ... with the regEx stuff that you don't want. Lol. Code: Copy Dim text As String ="Today #I# got to #experiment# #with# reef. I #needed# this to try #and# see if #I# can #wrap# it with #BANano#.png" Dim pattern As String = "#(.*?)#" Dim Matcher1 As Matcher Dim l As List : l.initialize Matcher1 = Regex.Matcher(pattern, text) Do While Matcher1.Find Log("Found: " & Matcher1.Group(1)) l.Add(Matcher1.Group(1)) Loop Upvote 0
Well ... with the regEx stuff that you don't want. Lol. Code: Copy Dim text As String ="Today #I# got to #experiment# #with# reef. I #needed# this to try #and# see if #I# can #wrap# it with #BANano#.png" Dim pattern As String = "#(.*?)#" Dim Matcher1 As Matcher Dim l As List : l.initialize Matcher1 = Regex.Matcher(pattern, text) Do While Matcher1.Find Log("Found: " & Matcher1.Group(1)) l.Add(Matcher1.Group(1)) Loop