Template talk:Str sub old

editprotected This template is protected in a broken state as it returns characters in the range  (which means it actually returns length + 1 characters, ending in the right spot but starting one step early): The output " 5678 " is incorrect as the "5" should not be part of it.

See Comparison of programming languages (string functions). This does not match the syntax of any known language. Please fix. — CharlotteWebb 03:04, 14 June 2009 (UTC)


 * Done. Dragons flight (talk) 03:33, 14 June 2009 (UTC)


 * Yes, but did that affect anything? I think it may have.  Bob the Wikipedian (talk • contribs) 17:16, 16 June 2009 (UTC)

Please add nocategory
Like I did with Str sub long, this template should use " |nocategory= " to allow example pages that generate errors to mark those as intentional. That way these pages do not show up on Category:Pages_with_incorrect_formatting_templates_use. Thanks! — SkyLined (talk) 10:58, 4 November 2009 (UTC)

Possibly unused code
I think that the second and third lines of this code are never reached. In the first line it checks whether = 0, so the condition  < 1 is never true. In theory, < 1 could also include negative numbers, but as the template doesn't handle a negative start parameter anyway,  < 1 appears to be the same as  = 0. Can you check this? --Entlinkt (talk) 15:24, 18 December 2009 (UTC)

length = 0 border case
This template behaves quite similar to the #sub parser function for start ≥ 0 and length > 0, but differently in the length = 0 border case. The template returns an empty string, while #sub would return the entire rest of the string. Examples:


 * returns nothing
 * returns cream (verify)

Should this be aligned? Effectively, length = 0 would result in the same as Template:Str right, similarly to start = 0 being the same as Template:Str left. --Entlinkt (talk) 15:24, 18 December 2009 (UTC)


 * Returning nothing (the substring of zero length) seems the logical thing to do. Calling the template with an explicit 0 is useless, but it may be the result of a computation.--Patrick (talk) 09:19, 12 July 2010 (UTC)

Apparent space characters in the result
Be aware that the result does not contain true space characters. Note the behaviour of the following:


 * is → is
 * is → is

Any template which relies on finding spaces in the result from Str sub (or alternative versions) will not produce the right result. Peter coxhead (talk) 09:54, 15 December 2011 (UTC)

Use new lua invoke command to greatly reduce the size/complexity of this template
Please use the new lua invoke command to greatly reduce the size and complexity of this template -- it'll greatly reduce the burden on the backend servers. Here's the code that you can use, copy/paste format: Try it out for yourself,   will return String. Thanks, Banaticus (talk) 00:30, 21 February 2013 (UTC)
 * Red information icon with gradient background.svg Not done for now: This is a major change; per WP:TESTCASES please put your proposed code in Template:Str sub/sandbox and prepare some tests at Template:Str sub/testcases which demonstrate that existing functionality is not compromised. -- Red rose64 (talk) 12:35, 21 February 2013 (UTC)
 * Note that the proposed code is nowhere near correct. And it's already done now, correctly. Anomie⚔ 02:11, 22 February 2013 (UTC)


 * Why was it nowhere near correct? It looks like mainly stylistic differences.  My version used explicit parameters instead of implicit parameters, and sub (which returns from i to j) instead of sublength.  The two position/length parameters don't need to be there, sub handles their absence by presuming either the start or end of the string.  Perhaps you were referring to array counting?  Lua normally starts at 1 instead of 0. Banaticus (talk) 02:58, 22 February 2013 (UTC)


 * For starters, because your new version wasn't functionally identical to the prior version. You can't convert str_sub to use named parameters like  when everyone has written their templates on the assumption that str_sub uses unnamed parameters.  That would break all of the existing templates that depend on this.  Similarly, the existing template specifies a start and a length for the substring, and not a start and an end.  Hence "sublength" and not "sub".  Dragons flight (talk) 03:07, 22 February 2013 (UTC)


 * Thanks. This is a good start, but we don't want to get to a point where we tell people, "here's the way lua works everywhere, except on the English Wikipedia where there are these strange quirks, namely (1), (2), and perhaps a few others that we haven't noted down in this reference document yet..."  I think that this template should use {{#expr: functions to add 1 to the implicit parameter which is then sent to sublength, so that other people who use sublength will see it function as expected in lua (with an array starting at 1 instead of 0).  I think that any templates which call this one should be changed to instead directly call the lua string sub function instead of this template, which should be deprecated.  I used explicit parameters because that's how the sub function was set up to work, after an initial run with implicit parameters, but if this template was deprecated then it wouldn't matter any more. Banaticus (talk) 18:19, 22 February 2013 (UTC)


 * The only problem I have with this is that it changes the parameters of how this template works. Currently the template goes B (0 is the first character) characters from A  whereas this lua module goes from X (1 is the first character) to Y.
 * Template: {{Tlp|Str sub old|ThisStringHere|4|6}} → {{Str sub old|ThisStringHere|4|6}}
 * Module: {{Tlc|1= # invoke:String|2=sub|3=s=ThisStringHere|4=i=4|5=j=6}} → {{#invoke:String|sub|s=ThisStringHere|i=4|j=6}}
 * Make those match, show the performance differences, and I would likely agree this is a good idea. Technical 13 (talk) 14:03, 5 June 2013 (UTC)

"Template:Str sub old/any" listed at Redirects for discussion
A discussion is taking place to address the redirect Template:Str sub old/any. The discussion will occur at Redirects for discussion/Log/2021 April 26 until a consensus is reached, and readers of this page are welcome to contribute to the discussion. User:GKFXtalk 11:32, 26 April 2021 (UTC)

"Template:Substr quick" listed at Redirects for discussion
A discussion is taking place to address the redirect Template:Substr quick. The discussion will occur at Redirects for discussion/Log/2021 April 26 until a consensus is reached, and readers of this page are welcome to contribute to the discussion. User:GKFXtalk 11:36, 26 April 2021 (UTC)