diff --git a/lecture/03_Variablen/03_Variablen.tex b/lecture/03_Variablen/03_Variablen.tex index 38fb270..7163e19 100644 --- a/lecture/03_Variablen/03_Variablen.tex +++ b/lecture/03_Variablen/03_Variablen.tex @@ -1,4 +1,4 @@ -% !TeX document-id = {dc20ae76-71b7-4d65-b662-f71c46d32e15} +\usepackage{blkarray}% !TeX document-id = {dc20ae76-71b7-4d65-b662-f71c46d32e15} % !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape] \input{../global.tex} @@ -97,6 +97,34 @@ \subsection{Zuweisung} % \maketitle %\subtitle{Konsoleneingabe} + +\section{Exkurs: String Templates} +\begin{frame} + \slidehead + + \begin{itemize}[<+->] + \item \textbf{Ziel}: Ausdrücke in einem \inlinekotlin{String} einfügen + \item Kann man so machen + \kotlinfile{listings/string_no_template.kts} + \item Aber so ist besser + \kotlinfile{listings/string_template.kts} + \end{itemize} +\end{frame} + +\begin{frame} + \slidehead + + \begin{itemize}[<+->] + \item \textbf{Problem}: Komplexere Ausdrücke gehen nicht + \kotlinfile{listings/string_template_complex_mistake.kts} + \item \textbf{Lösung}: Geschweifte klammern \inlinekotlin{\$\{ ... \}} + \kotlinfile{listings/string_template_complex.kts} + \end{itemize} + \begin{block}{Hinweis} + Ausdrücke mit \inlinekotlin{.} brauchen die Klammern + \end{block}\ +\end{frame} + \section{Exkurs: Konsoleneingabe} \begin{frame} \slidehead diff --git a/lecture/03_Variablen/listings/string_no_template.kts b/lecture/03_Variablen/listings/string_no_template.kts new file mode 100644 index 0000000..03ab70a --- /dev/null +++ b/lecture/03_Variablen/listings/string_no_template.kts @@ -0,0 +1,2 @@ +val x = 5 +val result = "The result is " + x + " euros" diff --git a/lecture/03_Variablen/listings/string_template.kts b/lecture/03_Variablen/listings/string_template.kts new file mode 100644 index 0000000..a1927e5 --- /dev/null +++ b/lecture/03_Variablen/listings/string_template.kts @@ -0,0 +1,2 @@ +val x = 5 +val result = "The result is $x euros" diff --git a/lecture/03_Variablen/listings/string_template_complex.kts b/lecture/03_Variablen/listings/string_template_complex.kts new file mode 100644 index 0000000..33012cb --- /dev/null +++ b/lecture/03_Variablen/listings/string_template_complex.kts @@ -0,0 +1,2 @@ +val y = "Fritz" +val result = "Your name has ${y.length} letters" diff --git a/lecture/03_Variablen/listings/string_template_complex_mistake.kts b/lecture/03_Variablen/listings/string_template_complex_mistake.kts new file mode 100644 index 0000000..7fe020e --- /dev/null +++ b/lecture/03_Variablen/listings/string_template_complex_mistake.kts @@ -0,0 +1,2 @@ +val y = "Fritz" +val result = "Your name has $y.length letters"