StrRept and StrCount

Propose new features and changes
User avatar
Posts: 5939
Joined: 19 Dec 2016, 01:58
Location: UK

StrRept and StrCount

20 Jul 2017, 11:13

StrSplit [v1.1.13+] [ - August 27, 2013]
Format [v1.1.17+] [ - December 27, 2014]
StrReplace [v1.1.21+] [ - March 28, 2015]
StrRept [v1.1.27+?]
StrCount [v1.1.27+?]

StrReplace, Format, and StrSplit, have been game-changers.

I had written some similar functions, but the standard functions meant that there was a common currency that all could use, and that I could provide tips/support for, versus everyone using their own individual incompatible functions, and including them with every script, or using the previously available less-advantageous standard methods.

I had wanted a StrRept function since day one of AutoHotkey, and when StrReplace provided a Count parameter, I allowed for the possibility that that might be sufficient, but from experience it turned out that the string count functionality was sufficiently useful in its own right to deserve a separate function.

I think it's only natural that there be a way to repeat strings, Send has a way to repeat keypresses, RegEx has a way to search for/replace a repeated string and Format has a way to repeat spaces or zeros.

I've thought very carefully about what functions I should recommend for AutoHotkey, and with these functions, in contrast to other proposals, the functions have: names, a parameter order, and functionality, that are reasonably natural and uncontroversial.

Also, I believe that these functions fit within the ethos of AutoHotkey, that of: simple, easy to use, easy to understand functions for beginners. Common, core functions.

The functions are not just useful in and of themselves, but useful for all sorts of hacks and unintended non-obvious uses. I have demonstrated that sort of mentality and approach in my link here, to stretch a function beyond its original use.
string hacks - AutoHotkey Community

Thanks for reading.

My prototype functions at present:

Code: Select all

JEE_StrRept(vText, vNum)
	return StrReplace(Format("{:" vNum "}","")," ",vText)
	;return StrReplace(Format("{:0" vNum "}",0),0,vText)

JEE_StrCount(ByRef vText, vNeedle, vCaseSen=0)
	if (vNeedle = "")
		return ""
	;note: StrReplace might also benefit from a case-sensitive parameter
	vSCS := A_StringCaseSense
	StringCaseSense, % vCaseSen ? "On" : "Off"
	StrReplace(vText, vNeedle, "", vCount) ;seemed to be faster than line below
	;StrReplace(vText, vNeedle, vNeedle, vCount)
	StringCaseSense, % vSCS
	return vCount
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 10 guests