summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Examples/example8.se
blob: 9274d14bfebd33ccf0b7709dc71d9b17f63ff42d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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));