jonson1986 Posted June 6, 2016 Share Posted June 6, 2016 Hello, I'm in need to generate different tags separated with comma (,) from a specific keyword by adding list of words at the end of my keyword... For example My keyword: Cost and Management Accounting List of words: 2014 2015 2016 Output should be similar like this Cost and Management Accounting 2014, Cost and Management Accounting 2015, Cost and Management Accounting 2016, Please help me to make it possible, Thanks Link to comment Share on other sites More sharing options...
orbs Posted June 6, 2016 Share Posted June 6, 2016 @jonson1986, welcome to AutoIt and to the forum. look at the AutoIt help: AutoIt \ Language Reference \ Operators. you'll notice this: Concatenation operators & Concatenates/joins two strings. e.g. "one" & 10 (equals "one10") &= Concatenation assignment. e.g. $vVar = "one", and then $vVar &= 10 ($vVar now equals "one10") Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
jonson1986 Posted June 6, 2016 Author Share Posted June 6, 2016 thanks orbs but I'm unable to find and understand what are you trying to guide me, even i tried to find the reference path you quoted but unable to find anything, please guide me in more details so it can make sense for me good day Link to comment Share on other sites More sharing options...
AutoBert Posted June 6, 2016 Share Posted June 6, 2016 47 minutes ago, jonson1986 said: even i tried to find the reference path you quoted but unable to find anything here is the reference: and the autoit helpfile is the best help i ever seen for programing language on a windows os. Link to comment Share on other sites More sharing options...
Trong Posted June 6, 2016 Share Posted June 6, 2016 Example: Global $keyword = "Cost and Management Accounting" Global $ListOfWords = "2014" & @CR & "2015" & @CR & "2016" Global $ListWords = StringSplit($ListOfWords, @CR) Global $nTag If Not IsArray($ListWords) Then Exit For $i = 1 To $ListWords[0] $nTag &= $keyword & $ListWords[$i] & ", " Next If StringRight($nTag, 2) = ", " Then $nTag = StringTrimRight($nTag, 2) ConsoleWrite("! New Tags: " & $nTag & @CRLF) MsgBox(64, "New Tags", $nTag) 3 hours ago, orbs said: [...] Concatenation operators & Concatenates/joins two strings. e.g. "one" & 10 (equals "one10") &= Concatenation assignment. e.g. $vVar = "one", and then $vVar &= 10 ($vVar now equals "one10") https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm Regards, Link to comment Share on other sites More sharing options...
jonson1986 Posted June 7, 2016 Author Share Posted June 7, 2016 Hello, whenever i tried to convert more than one keyword into tags, very first keyword give desired results such as below; Cost and Management Accounting 2014, Cost and Management Accounting 2015, Cost and Management Accounting 2016 and when script try to convert 2nd keyword into tags it also includes the previously generated tags as output such as below Cost and Management Accounting 2014, Cost and Management Accounting 2015, Cost and Management Accounting 2016, Research Methods 2014, Research Methods 2015, Research Methods 2016 But I want separate output for each tags, I think due to use of Globals this things is happening, please guide me how can i fix it Thanks here is my code ;============Generating Tags for 1st keyword===================== sleep(50) Global $keyword = FileRead (@scriptdir & "\replacing01.txt") Global $ListOfWords = " 2014" & @CR & " 2015" & @CR & " 2016" Global $ListWords = StringSplit($ListOfWords, @CR) Global $nTag If Not IsArray($ListWords) Then Exit For $i = 1 To $ListWords[0] $nTag &= $keyword & $ListWords[$i] & ", " Next If StringRight($nTag, 2) = ", " Then $nTag = StringTrimRight($nTag, 2) ConsoleWrite("! New Tags: " & $nTag & @CRLF) FileWrite (@scriptdir & "\tags01.txt", $nTag) ;============Generating Tags for 2st keyword===================== sleep(50) Global $keyword = FileRead (@scriptdir & "\replacing02.txt") Global $ListOfWords = " 2014" & @CR & " 2015" & @CR & " 2016" Global $ListWords = StringSplit($ListOfWords, @CR) Global $nTag If Not IsArray($ListWords) Then Exit For $i = 1 To $ListWords[0] $nTag &= $keyword & $ListWords[$i] & ", " Next If StringRight($nTag, 2) = ", " Then $nTag = StringTrimRight($nTag, 2) ConsoleWrite("! New Tags: " & $nTag & @CRLF) FileWrite (@scriptdir & "\tags02.txt", $nTag) Link to comment Share on other sites More sharing options...
orbs Posted June 7, 2016 Share Posted June 7, 2016 (edited) without getting into the obvious modification (i.e. declare all globals once and put the main code in a loop), you just need to empty the variable $nTag at the end of each section. meaning, put this line $nTag="" just after you do the FileWrite at the end of each section, before the next section begins. Edited June 7, 2016 by orbs Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
Trong Posted June 7, 2016 Share Posted June 7, 2016 ;============Generating Tags for 1st keyword===================== _MakeFileTag(@ScriptDir & "\tags01.txt", @ScriptDir & "\replacing01.txt", "2014,2015,2016", ",") ;============Generating Tags for 1st keyword===================== _MakeFileTag("tags02.txt", "replacing02.txt", "2014,2015,2016", ",") Func _MakeFileTag($FileKeyword, $FileTagsOUT, $ListOfWords, $sDelimitersListWord = ",") If Not FileExists($FileKeyword) Then Return SetError(1, 0, 0) ConsoleWrite("! File Keyword : " & $FileKeyword & @CRLF & "+ List Of Words: " & $ListOfWords & @CRLF) Local $Keyword = FileRead($FileKeyword) Local $hOpenFileTag = FileOpen($FileTagsOUT, 2 + 8 + 256) Local $nTag = _MakeTags($Keyword, $ListOfWords, $sDelimitersListWord) If Not @error And $nTag <> "" Then ConsoleWrite("+ New Tags : " & $nTag & @CRLF & "! File Tag OUT : " & $FileTagsOUT & @CRLF & @CRLF) FileWrite($hOpenFileTag, $nTag) Return SetError(0, FileClose($hOpenFileTag), 1) Else FileClose($hOpenFileTag) ConsoleWrite("! New Tags : Error !" & @CRLF & @CRLF) Return SetError(2, FileDelete($FileTagsOUT), 0) EndIf EndFunc ;==>_MakeFileTag Func _MakeTags($sKeyword, $sListWord, $sDelimitersListWord = ",") Local $nTagOutput, $aListWord = StringSplit($sListWord, $sDelimitersListWord) If Not IsArray($aListWord) Then Return SetError(1, 0, "") For $i = 1 To $aListWord[0] $nTagOutput &= StringStripWS($sKeyword & " " & $aListWord[$i], 7) & ", " Next If StringRight($nTagOutput, 2) = ", " Then $nTagOutput = StringTrimRight($nTagOutput, 2) Return SetError(0, 0, $nTagOutput) EndFunc ;==>_MakeTags Regards, 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