Jump to content

Recommended Posts

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
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:

  Reveal hidden contents

 

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

 

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

 

Posted
  On 8/22/2017 at 11:04 PM, 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

 

Expand  

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

Posted
  On 8/22/2017 at 2:58 PM, 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

 

Expand  

I got output using this

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...