Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
search text for special characters
#1
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!
#2
Macro Macro1571
Code:
Copy      Help
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]
#3
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....
#4
What is your code? My code gives correct results for your example.

Macro Macro1571
Code:
Copy      Help
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
#5
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?
#6
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]}"
#7
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?
#8
Macro Macro1571
Code:
Copy      Help
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
#9
merci beaucoup!

One last question... how can i remove the hashtag from the results?
#10
use replacerx

Macro Macro1571
Code:
Copy      Help
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
#11
Macro Macro1571
Code:
Copy      Help
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


Forum Jump:


Users browsing this thread: 9 Guest(s)