Jump to content
Sign in to follow this  
jonson1986

Generate Tags

Recommended Posts

jonson1986

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

 

Share this post


Link to post
Share on other sites
orbs

@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")

 

Share this post


Link to post
Share on other sites
jonson1986

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

Share this post


Link to post
Share on other sites
AutoBert
47 minutes ago, jonson1986 said:

even i tried to find the reference path you quoted but unable to find anything

here is the reference:

77_AutoIt Help (v3.3.14.2).jpg

and the autoit helpfile is the best help i ever seen for programing language on a windows os.

Share this post


Link to post
Share on other sites
VIP

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,
 

Share this post


Link to post
Share on other sites
jonson1986

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)

 

Share this post


Link to post
Share on other sites
orbs

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 by orbs

Share this post


Link to post
Share on other sites
VIP
;============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,
 

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.