Posts: 97
Threads: 48
Joined: Sep 2010
Hello,
Is it possible to search for special characters like a hashtag or something (eg #power) in a text and all other words with a hashtag, store them and use them later seperately...
so for example i have a text like this:
This is an example #text with several hashtags and i want the #words with the #hashtags filtered out so i can use them later for further #actions.
I can search for the '#' and any character behind it, but i don't know how to store and use it for later...
maybe somebody can help me or even give me some example code?
Thanks in advance!
Posts: 12,073
Threads: 140
Joined: Dec 2002
Macro
Macro1571
str s=
;This is an example #text with several hashtags and i want the #words with the #hashtags filtered out so i can use them later for further #actions.
ARRAY(str) a
findrx(s "#\w+" 0 4 a)
int i
for i 0 a.len
,out a[0 i]
Posts: 97
Threads: 48
Joined: Sep 2010
Thanks for your answer!
But when i use this and there is a text and there is something like this:
#one #two
#three
#four
it recognises it like #one#two#three#four??? and not like seperate one's... everything is 'separated by a space or linebreak... and i need it as separate values so i can use it further... hope this is possible....
Posts: 12,073
Threads: 140
Joined: Dec 2002
What is your code? My code gives correct results for your example.
Macro
Macro1571
str s=
;#one #two
;#three
;#four
ARRAY(str) a
findrx(s "#\w+" 0 4 a)
out a.len
int i
for i 0 a.len
,out a[0 i]
output:
4
#one
#two
#three
#four
Posts: 97
Threads: 48
Joined: Sep 2010
I'm sorry
You're right i used something different the code you suppied me with was correct (of course!)
How can i use the for example third result in a text again? like in a textbox? or use it with a findreplace action?
Posts: 12,073
Threads: 140
Joined: Dec 2002
a[0 0], a[0 1] and so on are variables, and can be used anywhere.
mes a[0 2] ;;shows third result
mes F"third result is: {a[0 2]}"
Posts: 97
Threads: 48
Joined: Sep 2010
Ok thanks for the explanation! but another question if i may... the [0 1] [0 2] and so on thing i understand but if i want to prepare a text with all the results in it how can i manage this? every search has a different number of results and when i use for example [0 10] and it is not there i get an error... is there a way to do something like [0 1] [0 2] till end with my own text in between... so counting and when empty it stops?
Posts: 12,073
Threads: 140
Joined: Dec 2002
Macro
Macro1571
str s=
;#one #two
;#three
;#four
ARRAY(str) a
findrx(s "#\w+" 0 4 a)
out a.len
int i
str s2
for i 0 a.len
,s2+F"aaaaaaa {a[0 i]} bbbbb[]"
out s2
Posts: 97
Threads: 48
Joined: Sep 2010
merci beaucoup!
One last question... how can i remove the hashtag from the results?
Posts: 576
Threads: 97
Joined: Aug 2007
use replacerx
Macro
Macro1571
str s=
;#one #two
;#three
;#four
ARRAY(str) a
findrx(s "#\w+" 0 4 a)
out a.len
int i
str s2
for i 0 a.len
,s2+F"aaaaaaa {a[0 i]} bbbbb[]"
s2.replacerx("#" "")
out s2
Posts: 12,073
Threads: 140
Joined: Dec 2002
Macro
Macro1571
str s=
;#one #two
;#three
;#four
ARRAY(str) a
findrx(s "(?<=#)\w+" 0 4 a)
int i
str s2
for i 0 a.len
,s2+F"aaaaaaa {a[0 i]} bbbbb[]"
out s2