summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Examples/example8.se
diff options
context:
space:
mode:
Diffstat (limited to 'Sencha-lang/Examples/example8.se')
-rw-r--r--Sencha-lang/Examples/example8.se60
1 files changed, 60 insertions, 0 deletions
diff --git a/Sencha-lang/Examples/example8.se b/Sencha-lang/Examples/example8.se
new file mode 100644
index 0000000..9274d14
--- /dev/null
+++ b/Sencha-lang/Examples/example8.se
@@ -0,0 +1,60 @@
+println("Some string manipulation");
+
+text = "When I was young, everything was simpler.";
+
+println("Our text looks like that:");
+println(text);
+
+x = 0;
+while(x < 4)
+{
+ print(text[x]);
+ x = x +1;
+}
+
+print("\n");
+
+println("We can replace some content of the text, for example \" whatever \" ");
+
+println("But first, let's try some simple replacement!");
+
+text[5] = "M";
+text[3] = "K";
+
+println("Now text is: ", text);
+
+println("Let's define some useful functions for us:");
+
+def slice(text, from, to)
+{
+ bit = "";
+ i = from;
+ while(i < to)
+ {
+ bit = bit + text[i];
+ i = i + 1;
+ }
+ return bit;
+}
+
+println("We defined slice, let\'s try it now!");
+
+println(slice(text, 0, 8));
+
+println("And some more: ", slice(text, 9, 14));
+
+println("Sweet!");
+println("What about replace function?");
+
+def replace(text, replacement, start_position, end_position)
+{
+ prefix = slice(text, 0, start_position);
+ suffix = slice(text, end_position, len(text));
+ result = prefix + replacement + suffix;
+ return result;
+}
+
+println("It looks pretty simple. Lets replace some text!");
+
+println("Original: ", text);
+println("After replacement: ", replace(text, "nice", 11, 16)); \ No newline at end of file