Jump to content

Search the Community

Showing results for tags '_generatevar_autosplit'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. Whenever I embed strings in code that contain quotes I have to separate them very carefully, so I wrote this function to do it automatically correctly: ; #FUNCTION# ==================================================================================================================== ; Name...........: _QuoteAutoIt ; Description ...: Wraps a string in AutoIt-compatible quotes (single or double) with minimal escaping. ; Syntax.........: _QuoteAutoIt($s) ; Parameters ....: $s - The input string. ; Return values .: The quoted string literal. ; Author ........: Adapted for use in _GenerateVar_AutoSplit(). ; =============================================================================================================================== Func _QuoteAutoIt($s) ; Case 1: contains double-quote but no single-quote -> wrap with single-quotes If StringInStr($s, '"') And Not StringInStr($s, "'") Then Return "'" & $s & "'" ; Case 2: contains single-quote but no double-quote -> wrap with double-quotes ElseIf Not StringInStr($s, '"') And StringInStr($s, "'") Then Return '"' & $s & '"' ; Case 3: contains both, or neither -> escape double-quotes and use double-quotes wrapper Else $s = StringReplace($s, '"', '""') Return '"' & $s & '"' EndIf EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _GenerateVar_AutoSplit ; Description ...: Generates AutoIt source code that assigns a string to a variable, automatically splitting long strings. ; Syntax.........: _GenerateVar_AutoSplit($sString, $sVarName [, $iLen = 1000]) ; Parameters ....: $sString - The input string. ; $sVarName - The variable name (with or without leading $). ; $iLen - [optional] Maximum chunk length per line. Default is 1000. ; Return values .: String containing AutoIt code lines for variable assignment. ; Author ........: Dao Van Trong - TRONG.PRO ; Remarks .......: - If the string is empty, returns "$VarName = ''". ; - Uses _QuoteAutoIt() for proper quoting. ; =============================================================================================================================== Func _GenerateVar_AutoSplit($sString, $sVarName='VarName', $iLen = 1000) ; Ensure variable name starts with $ If StringLeft($sVarName, 1) <> "$" Then $sVarName = "$" & $sVarName ; Validate chunk length If Not IsInt($iLen) Then $iLen = Int($iLen) If $iLen < 1 Then $iLen = 1 ; Convert to string if not already If Not IsString($sString) Then $sString = String($sString) Local $iTotal = StringLen($sString) If $iTotal = 0 Then ; Empty string Return $sVarName & " = " & _QuoteAutoIt("") EndIf Local $sOut = "" Local $iPos = 1 Local $bFirstLine = True While $iPos <= $iTotal Local $sPiece = StringMid($sString, $iPos, $iLen) Local $sQuoted = _QuoteAutoIt($sPiece) If $bFirstLine Then $sOut &= $sVarName & " = " & $sQuoted & @CRLF $bFirstLine = False Else $sOut &= $sVarName & " &= " & $sQuoted & @CRLF EndIf $iPos += $iLen WEnd ; Remove trailing CRLF Return StringTrimRight($sOut, StringLen(@CRLF)) EndFunc
×
×
  • Create New...