sree161 Posted August 22, 2017 Share Posted August 22, 2017 (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 August 22, 2017 by sree161 Link to comment Share on other sites More sharing options...
water Posted August 22, 2017 Share Posted August 22, 2017 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
mikell Posted August 22, 2017 Share Posted August 22, 2017 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 sree161 1 Link to comment Share on other sites More sharing options...
Malkey Posted August 22, 2017 Share Posted August 22, 2017 This example assumes the last two elements of the generated array always require the same string manipulation as displayed in Post #1 Output. expandcollapse popupLocal $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 sree161 1 Link to comment Share on other sites More sharing options...
sree161 Posted August 23, 2017 Author Share Posted August 23, 2017 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. expandcollapse popupLocal $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 Link to comment Share on other sites More sharing options...
sree161 Posted August 23, 2017 Author Share Posted August 23, 2017 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now