sree161

is there any specific command to copy text between particulat string??

6 posts in this topic

#1 ·  Posted (edited)

Hi
i have  a text file which has a specific word i.e name 7 or 8 times in it along with some other text.
i have to pick text between each "name" and save it to an array.

can someone help me with the logic?

Eg:
Input:
sajfkjdsaf
name
ajhsdfkajfdajsjdflkjafa
afdhjsahlfkaf
ajfkhdsakfasf
akjfkjafd
name
asfjksajf
kdajsfpa
alkdshfahsf
nameajslkfja
aslkfajnbfajn
Output:
$s[1]: sajfkjdsaf
$s[2]: ajhsdfkajfdajsjdflkjafa
afdhjsahlfkaf
ajfkhdsakfasf
akjfkjafd
$s[3]:
asfjksajf
kdajsfpa
alkdshfahsf
nameajslkfja
aslkfajnbfajn
asfjksajf
$s[4]
kdajsfpa
alkdshfahsf
nameajslkfja
aslkfajnbfajn

 

 

can some one help me in this??

 

Thaks in advance,

sree161

Edited by sree161

Share this post


Link to post
Share on other sites



#2 ·  Posted

Can you post an example what you expect as output based on your input?

What have you tried so far?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

water, it's not very clear but input and output are written in the provided text - I suppose so :)

sree161
You might try StringSplit with "name" as delimiter and the flag $STR_ENTIRESPLIT

 

1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted

This example assumes the last two elements of the generated array always require the same string manipulation as displayed in Post #1 Output.

Local $Input = _
        "sajfkjdsaf" & @CRLF & _
        "name" & @CRLF & _
        "ajhsdfkajfdajsjdflkjafa" & @CRLF & _
        "afdhjsahlfkaf" & @CRLF & _
        "ajfkhdsakfasf" & @CRLF & _
        "akjfkjafd" & @CRLF & _
        "name" & @CRLF & _
        "asfjksajf" & @CRLF & _
        "kdajsfpa" & @CRLF & _
        "alkdshfahsf" & @CRLF & _
        "nameajslkfja" & @CRLF & _
        "aslkfajnbfajn"

$s = StringSplit($Input & "name" & @CRLF, "name" & @CRLF, 1) ; $STR_ENTIRESPLIT (1) = entire delimiter string is needed to mark the split
$iLRI = UBound($s) - 1 ; Last Array Index
$s[$iLRI] = @CRLF & StringRegExpReplace($s[$iLRI - 1], "^.+\v+(?s)(.+)$", "$1") ; Add preceeding line feed, and, remove first line of $s[2nd last array index].  This become $s[last array index].
$s[$iLRI - 1] = @CRLF & $s[$iLRI - 1] & @CRLF & StringRegExpReplace($s[$iLRI - 1], "(^.+\v+)(?s).+$", "$1") ; Add preceeding line feed, and, add  copy of first line of $s[2nd last array index to end of $s[2nd last array index]

Local $sDisplay = "Output;" & @CRLF
For $i = 1 To UBound($s) - 1
    $sDisplay &= "$s[" & $i & "]: " & $s[$i]
Next
;ConsoleWrite($sDisplay & @CRLF)
MsgBox(0, "Results", $sDisplay)

#cs ; From Post #1
    Output:
    $s[1]: sajfkjdsaf
    $s[2]: ajhsdfkajfdajsjdflkjafa
    afdhjsahlfkaf
    ajfkhdsakfasf
    akjfkjafd
    $s[3]:
    asfjksajf
    kdajsfpa
    alkdshfahsf
    nameajslkfja
    aslkfajnbfajn
    asfjksajf
    $s[4]
    kdajsfpa
    alkdshfahsf
    nameajslkfja
    aslkfajnbfajn
#ce

 

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted

6 hours ago, Malkey said:

This example assumes the last two elements of the generated array always require the same string manipulation as displayed in Post #1 Output.

Local $Input = _
        "sajfkjdsaf" & @CRLF & _
        "name" & @CRLF & _
        "ajhsdfkajfdajsjdflkjafa" & @CRLF & _
        "afdhjsahlfkaf" & @CRLF & _
        "ajfkhdsakfasf" & @CRLF & _
        "akjfkjafd" & @CRLF & _
        "name" & @CRLF & _
        "asfjksajf" & @CRLF & _
        "kdajsfpa" & @CRLF & _
        "alkdshfahsf" & @CRLF & _
        "nameajslkfja" & @CRLF & _
        "aslkfajnbfajn"

$s = StringSplit($Input & "name" & @CRLF, "name" & @CRLF, 1) ; $STR_ENTIRESPLIT (1) = entire delimiter string is needed to mark the split
$iLRI = UBound($s) - 1 ; Last Array Index
$s[$iLRI] = @CRLF & StringRegExpReplace($s[$iLRI - 1], "^.+\v+(?s)(.+)$", "$1") ; Add preceeding line feed, and, remove first line of $s[2nd last array index].  This become $s[last array index].
$s[$iLRI - 1] = @CRLF & $s[$iLRI - 1] & @CRLF & StringRegExpReplace($s[$iLRI - 1], "(^.+\v+)(?s).+$", "$1") ; Add preceeding line feed, and, add  copy of first line of $s[2nd last array index to end of $s[2nd last array index]

Local $sDisplay = "Output;" & @CRLF
For $i = 1 To UBound($s) - 1
    $sDisplay &= "$s[" & $i & "]: " & $s[$i]
Next
;ConsoleWrite($sDisplay & @CRLF)
MsgBox(0, "Results", $sDisplay)

#cs ; From Post #1
    Output:
    $s[1]: sajfkjdsaf
    $s[2]: ajhsdfkajfdajsjdflkjafa
    afdhjsahlfkaf
    ajfkhdsakfasf
    akjfkjafd
    $s[3]:
    asfjksajf
    kdajsfpa
    alkdshfahsf
    nameajslkfja
    aslkfajnbfajn
    asfjksajf
    $s[4]
    kdajsfpa
    alkdshfahsf
    nameajslkfja
    aslkfajnbfajn
#ce

 

This is wat i was looking for thanks for the code again

Share this post


Link to post
Share on other sites

#6 ·  Posted

18 hours ago, mikell said:

water, it's not very clear but input and output are written in the provided text - I suppose so :)

sree161
You might try StringSplit with "name" as delimiter and the flag $STR_ENTIRESPLIT

 

I got output using this

 

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