List Alphabet A-Z in Smarty - foreach

I was searching for the web, but I only found a smarty plugin function for displaying the Alphabet from A to Z.
There are cases, when you couldn't add a new plugin, so how could you display it otherwise?

Its easy with pure smarty foreach.
{foreach item=i from='A'|#range:'Z'}
{$i}
{/foreach}

Related

Replace everything after specific character in google sheets

So I have a document with 30k+ emails. The probleme is, during the export random characters appeared after the emails, something like name#email.com2019-10-10T0545152019-10-10T054515f or name#email.com00000000000700392019-11-28T070033f
My question is, how do i remove everything after ".com" or ".fr" in all the cells ?
You could try using REGEXREPLACE.
=REGEXREPLACE(A1,"\.com.*|\.fr.*", "")
Try
=REGEXEXTRACT(A1,".+\.com|.+\.fr")
Working from what other people added, you can get all emails from the column A and use regular expressions to get the values. Using ARRAYFORMULA you can do it in a single formula:
=ARRAYFORMULA(IF(A:A<>""; REGEXEXTRACT(A:A; ".+\.(?:com|fr)"); ""))
Rundown
ARRAYFORMULA allows to execute the formula to the entire column
REGEXEXTRACT extracts part of the string using regular expressions
IF conditional. In this case it's used to no execute when the cell is empty, preventing an error.
References
ARRAYFORMULA (Docs Editor Help)
REGEXEXTRACT (Docs Editor Help)
IF (Docs Editor Help)
Supposing your raw-data email list were in A2:A, try this in, Row 2 of an otherwise empty column (e.g., B2):
=ArrayFormula(IF(A2:A="",,REGEXEXTRACT(A2:A,"^.+\.\D+")))
In plain English, this means "Extract everything up to the last dot found that is followed by some number of non-digits."
This should pull up to any suffix (e.g., .com, .co, .biz, .org, .ma.gov, etc.).

Sheets: use FILTER for multiple strings instead of exact match only?

I'm trying to SUM column C based on the contents of columns A and B. Like this:
=sum(filter(C:C, (A:A="Safari")*(B:B="10.0.1")))
The above formula works. The FILTER function works as an exact match for "Safari" and "10.0.1" for columns A and B respectively.
The problem is... this only captures an exact match: "10.0.1". I need to capture multiple strings e.g. "10.0.1", "10.0.2", "10.0.3", etc.
If helpful, here's an example sheet.
I'm not sure if regex can be used in combination with a filter function. In any case, I've tried hard and failed spectacularly. So... how best to filter for multiple strings instead of exact match only?
=SUMIFS(C:C,A:A,"Safari",B:B,"10.0.*")
Please try:
=filter(C:C, (A:A="Safari")*(REGEXMATCH(B:B, "10\.0\..*")))
Notes:
filter is an arrayformlula and it has a great property: it converts all the formulas inside it into array formulas
"10.0..*" is a regex for your match. "\." will match a dot, ".*" will match any sequence of chars. Please see more syntax here.

Countif with len in Google Spreadsheet

I have a column XXX like this :
XXX
A
Aruin
Avolyn
B
Batracia
Buna
...
I would like to count a cell only if the string in the cell has a length > 1.
How to do that?
I'm trying :
COUNTIF(XXX1:XXX30, LEN(...) > 1)
But what should I write instead of ... ?
Thank you in advance.
For ranges that contain strings, I have used a formula like below, which counts any value that starts with one character (the ?) followed by 0 or more characters (the *). I haven't tested on ranges that contain numbers.
=COUNTIF(range,"=?*")
To do this in one cell, without needing to create a separate column or use arrayformula{}, you can use sumproduct.
=SUMPRODUCT(LEN(XXX1:XXX30)>1)
If you have an array of True/False values then you can use -- to force them to be converted to numeric values like this:
=SUMPRODUCT(--(LEN(XXX1:XXX30)>1))
Credit to #greg who posted this in the comments - I think it is arguably the best answer and should be displayed as such. Sumproduct is a powerful function that can often to be used to get around shortcomings in countif type formulae.
Create another list using an =ARRAYFORMULA(len(XXX1:XXX30)>1) and then do a COUNTIF based on that new list: =countif(XXY1:XXY30,true()).
A simple formula that works for my needs is =ROWS(FILTER(range,LEN(range)>X))
The Google Sheets criteria syntax seems inconsistent, because the expression that works fine with FILTER() gives an erroneous zero result with COUNTIF().
Here's a demo worksheet
Another approach is to use the QUERY function.
This way you can write a simple SQL like statement to achieve this.
For example:
=QUERY(XXX1:XXX30,"SELECT COUNT(X) WHERE X MATCHES '.{1,}'")
To explain the MATCHES criteria:
It is a regex that matches every cell that contains 1 or more characters.
The . operator matches any character.
The {1,} qualifies that you only want to match cells that have at 1 or more characters in them.
Here is a link to another SO question that describes this method.

Parsing text content in ColdFusion

I am attempting to parse text from a <cfoutput query="...">. I am interested in finding the number of times every word in the text is displayed. For example:
"My name is Bob and I like to Bob".
should result in
Bob - 2
Name - 1
etc, etc, etc.
I take my <cfoutput> from a twitter RSS feed. Here is my code:
<blink>
<cfset feedurl="http://twitter.com/statuses/user_timeline/47847839.rss" />
<cftry>
<cffeed source="#feedurl#" properties="feedmeta" query="feeditems" />
<cfcatch></cfcatch>
</cftry>
<ol>
<cfoutput query="feeditems">
#content# #id# <br><br>
</cfoutput>
</ol>
</blink>
I output a pretty great ordered list, but I can't figure out for the life of me how to parse the content and list how many times each word is used.
Thanks for any help you can provide, I am new to these forums!
You can find a solution here:
http://www.coldfusionjedi.com/index.cfm/2007/8/2/Counting-Word-Instances-in-a-String
Basically, split the string up using regex and then loop over the results. There are some darn good comments here as well.

Markdown: How to reference an item in a numbered list, by number (like LaTeX's \ref / \label)?

Is there any way in markdown to do the equivalent of the cross-referencing in this LaTeX snippet? (Taken from here.)
\begin{enumerate}
\item \label{itm:first} This is a numbered item
\item Another numbered item \label{itm:second}
\item \label{itm:third} Same as \ref{itm:first}
\end{enumerate}
Cross-referencing items \ref{itm:second} and \ref{itm:third}.
This LaTeX produces
1. This is a numbered item
2. This is another numbered item
3. Same as 1
Cross-referencing items 2 and 3.
That is, I would like to be able to refer to items in a markdown list without explicitly numbering them, so that I could change the above list to the following without having to manually update the cross references:
1. This is the very first item
2. This is a numbered item
3. This is another numbered item
4. Same as 2
Cross-referencing items 3 and 4.
HTML can't even do that and Markdown is a subset of HTML, so the answer is no.
For example, your list would be represented like so (when rendered by Markdown):
<ol>
<li>This is a numbered item</li>
<li>This is another numbered item</li>
<li>Same as 1</li>
</ol>
Notice that there is no indication of which item is which as far as the numbering goes. That is all inferred at render time by the browser. However, the number values are not stored within the document and are not referenceable or linkable. They are for display only and serve no other purpose.
Now you could write some custom HTML to uniquely identify each list item and make them referenceable:
<ol>
<li id="item1">This is a numbered item</li>
<li id="item2">This is another numbered item</li>
<li id="item3">Same as <a href="#item1>1</a></li>
</ol>
However, those IDs are hardcoded and have no relation to the numbers used to display the items. Although, I suppose that's what you want. To make your updated changes:
<ol>
<li id="item0">This is the very first item</li>
<li id="item1">This is a numbered item</li>
<li id="item2">This is another numbered item</li>
<li id="item3">Same as 2</li>
</ol>
The IDs stay with the item as intended. However, lets move on to the links to those list items. Note that in the first iteration we had:
1
And with the update we had:
2
The only difference being the link's label (changed from "1" to "2"). That is actually changing the document text through some sort of macro magic stuff. Not something HTML can do, at least not without JavaScript and/or CSS to help.
In other words, the text of every reference to the item would need to be manually updated throughout the document every time the list is updated. And that is for HTML. What about Markdown? As the rules state:
Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags.
Therefore in standard Markdown there is not even any way to assign IDs to the list items.
Seems to me you either need to use something other than lists or use something other than Markdown/HTML.
Maybe you need to use the H1.. H6 and then Markdown generates an anchor that you can link to:
# H1
## H2
### H3
#### H4
##### H5
###### H6
Something like:
###### 1. This is a numbered item
###### 2. This is another numbered item
###### 3. Same as 1
Generates:
<h6 id="1-this-is-a-numbered-item">1. This is a numbered item</h6>
<h6 id="2-this-is-another-numbered-item">2. This is another numbered item</h6>
<h6 id="3-same-as-1">3. Same as 1</h6>
Pandoc allows you to use labels in example lists:
Numbered example lists
Extension: example_lists
The special list marker # can be used for sequentially numbered examples. The first list item with a # marker will be numbered '1', the next '2', and so on,
throughout the document. The numbered examples need not occur in a single list; each new list using # will take up where the last stopped. So, for example:
(#) My first example will be numbered (1).
(#) My second example will be numbered (2).
Explanation of examples.
(#) My third example will be numbered (3).
Numbered examples can be labeled and referred to elsewhere in the document:
(#good) This is a good example.
As (#good) illustrates, ...
The label can be any string of alphanumeric characters, underscores, or hyphens.

Resources