Jump to content
Sign in to follow this  
myspacee

Extract strings from text

Recommended Posts

myspacee

hello,

Searching help to extract some word between delimeters. I've more than 300 files by day to watch,

and try to make script that extract some info i need.

I semplify my text to this exaple :

asdaasdaasdaasdaasdaasdaasda>lion<asdaasdaasdaasdaasdaasdaasdaasdaasdaasda>zebra<asdaasdaasdaasdaasdaasdaasda>cat<asdaasdaasdaasdaasdaasdaasdaasdaasda>armadillo<asdaasdaasdaasdaasdaasdaasdaasda

as you can see in text, there are some delimeters : > <

I try to extract all text between > < symbols, and obtain this list:

>lion<
>zebra<
>cat<
>armadillo<

but need some help.

Thank you for any info,

m.

Share this post


Link to post
Share on other sites
wolf9228

hello,

Searching help to extract some word between delimeters. I've more than 300 files by day to watch,

and try to make script that extract some info i need.

I semplify my text to this exaple :

asdaasdaasdaasdaasdaasdaasda>lion<asdaasdaasdaasdaasdaasdaasdaasdaasdaasda>zebra<asdaasdaasdaasdaasdaasdaasda>cat<asdaasdaasdaasdaasdaasdaasdaasdaasda>armadillo<asdaasdaasdaasdaasdaasdaasdaasda

as you can see in text, there are some delimeters : > <

I try to extract all text between > < symbols, and obtain this list:

>lion<
>zebra<
>cat<
>armadillo<

but need some help.

Thank you for any info,

m.

$Text = "asdaasdaasdaasdaasdaasdaasda>lion<asdaasdaasdaasdaasdaasdaasdaasdaasdaasda>zebra<asdaasdaasdaasdaasdaasdaasda>cat<asdaasdaasdaasdaasdaasdaasdaasdaasda>armadillo<asdaasdaasdaasdaasdaasdaasdaasda"

MsgBox(0,"MSG",Extract($Text))

Func Extract($Text,$delimeterA = ">" ,$delimeterB = "<")
Local $ExtractText = ""
For $i = 1 To StringLen($Text)
$CharA = StringMid($Text,$i,1)
if $CharA == $delimeterA Then
For $j = $i + 1 To StringLen($Text)
$CharB = StringMid($Text,$j,1)
if $CharB == $delimeterB Then
$ExtractText &= StringMid($Text,$i + 1,($j - $i) - 1) & @CRLF
ExitLoop
Else
ContinueLoop
EndIf
Next
Else
ContinueLoop
EndIf
Next
Return $ExtractText
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
Varian

Here is one example:

#include <Array.au3>
$String = 'asdaasdaasdaasdaasdaasdaasda>lion<asdaasdaasdaasdaasdaasdaasdaasdaasdaasda>zebra<asdaasdaasdaasdaasdaasdaasda>cat<asdaasdaasdaasdaasdaasdaasdaasdaasda>armadillo<asdaasdaasdaasdaasdaasdaasdaasda'

$Array = StringRegExp($String, '>[^<>]+<', 3)
If IsArray($Array) Then _ArrayDisplay($Array)

Share this post


Link to post
Share on other sites
myspacee

thank you both, works like a charm

m.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.