How many integers between $1$ and $10^n$ contain $14$? How can we derive a formula to calculate the number of integers between $1$ and $10^n$ that contain the number $14$ (as a string)?
For example, there are $20$ integers from $1$ to $1000$ that contain at least one $14$:

"14","114","140","141","142","143","144","145","146","147","148","149","214","314","414","514","614","714","814","914"

 A: If the number if length-$n$ numbers containing $14$ is $f(n)$; call these numbers "good", then we have the recurrence $$f(n)=10 f(n-1)-f(n-2)+10^{n-2}$$ for $n \geq 3$: the argument is that we can construct length-$n$ good numbers from length-$(n-1)$ good numbers by appending any digit, or by appending $14$ to any length-$(n-2)$ number; this double-counts numbers with multiple $14$s ending in $14$, so we subtract $f(n-2)$ to account for this.
This gives the sequence $$0, 1, 20, 299, 3970, 49401, 590040, 6850999, 77919950, 872348501, \ldots.$$
A: This is a variant on Rebecca Stone's answer.  Let $G(n)$ count the number of "good" length-$n$ strings that contain a $14$, and let $B(n)$ count the number of "bad" strings that don't.  Clearly
$$G(n)+B(n)=10^n$$
You can create a bad string of length $n$ by appending any digit you want to a bad string of length $n-1$, unless the shorter string ends in a $1$, in which case you can't append a $4$.  The number of such strings (ending in a $1$) is $B(n-2)$.  Thus
$$B(n)=10B(n-1)-B(n-2)$$
with starting values $B(1)=10$ and $B(2)=99$.  This gives the the "bad" sequence
$$10, 99, 980, 9701, 96030, 950599, 9409960, 93149001,\ldots$$
which is A004189 in the OEIS, where it's noted that
$$B(n)={(5+\sqrt{24})^{n+1}-(5-\sqrt{24})^{n+1}\over2\sqrt{24}}$$
Thus
$$G(n)=10^n-{(5+\sqrt{24})^{n+1}\over2\sqrt{24}}+{(5-\sqrt{24})^{n+1}\over2\sqrt{24}}$$
as robjohn found.  
A: There are $\binom{n-k}{k}$ arrangements of $k$ "$14$"s and $10^{n-2k}$ other digits.
Thus, inclusion-exclusion says there are
$$
\sum_{k=1}^{\lfloor n/2\rfloor}(-1)^{k-1}\binom{n-k}{k}10^{n-2k}\tag{1}
$$
numbers from $1$ to $10^n$ which contain "$14$".
Here are some of the first few values.
$$
\begin{array}{r|l}
n&\text{count}\\
\hline
2&1\\
3&20\\
4&299\\
5&3970\\
6&49401\\
7&590040
\end{array}\tag{2}
$$

Generating Function
Multiply $(1)$ by $x^n$ and sum:
$$
\begin{align}
&\sum_{n=0}^\infty\sum_{k=1}^\infty(-1)^{k-1}\binom{n-k}{n-2k}10^{n-2k}x^n\\
&=\sum_{n=0}^\infty\sum_{k=1}^\infty(-1)^{n-k-1}\binom{-k-1}{n-2k}10^{n-2k}x^{n-2k}x^{2k}\\
&=\sum_{k=1}^\infty(-1)^{k-1}\frac{x^{2k}}{(1-10x)^{k+1}}\\
&=\frac1{10x-1}\frac{\frac{x^2}{10x-1}}{1-\frac{x^2}{10x-1}}\\
&=\frac{x^2}{1-20x+101x^2-10x^3}\tag{3}
\end{align}
$$
which has the Taylor series $x^2+20x^3+299x^4+3970x^5+49401x^6+590040x^7+\dots$

Closed Form
The denominator in $(3)$ says that $c_n$ satisfies
$$
c_n=20c_{n-1}-101c_{n-2}+10c_{n-3}\tag{4}
$$
The characteristic polynomial for $(4)$ is
$$
x^3-20x^2+101x-10\tag{5}
$$
whose roots are
$$
\left\{10,5+\sqrt{24},5-\sqrt{24}\right\}\tag{6}
$$
We can solve $(4)$ in the standard manner for such recurrences to get
$$
c_n=10^n-\frac{(5+\sqrt{24})^{n+1}}{2\sqrt{24}}+\frac{(5-\sqrt{24})^{n+1}}{2\sqrt{24}}\tag{7}
$$
A: Might not be a solution you want, but this little code snippet in Javascript does your work.
This returns 20 as an output for 1000. 
299 for 10000.
 var count = 0;
 for (i = 0; i < 1000; i++) {
 if (i.toString().search("14") != -1) {
     count++;
 }
 }
 alert(count);

