Последняя активность 1753208667

An example of how to swap certain words for underscores from a given input array

DraxCodes's Avatar DraxCodes ревизий этого фрагмента 1753208667. К ревизии

1 file changed, 2 insertions

Program.cs

@@ -5,6 +5,8 @@ public class Program
5 5 var script = new Scriptures();
6 6 var verse = script.GetRandomVerseWithHiddenWords();
7 7 Console.WriteLine(verse);
8 + // Example Output
9 + // 1 Nephi 3:7: ___ it came __ ____ that I, Nephi said ____ __ father: I ____ go and do the things _____ the Lord hath commanded...
8 10 }
9 11 }
10 12

DraxCodes's Avatar DraxCodes ревизий этого фрагмента 1753208318. К ревизии

1 file changed, 1 insertion, 1 deletion

Program.cs

@@ -28,7 +28,7 @@ public class Scriptures
28 28 {
29 29 var selectedScipture = GetRandomScripture();
30 30 string[] outPutverse = new string[selectedScipture.Length];
31 - var splitVerse = selectedScipture.Split(" ", StringSplitOptions.None);
31 + var splitVerse = selectedScipture.Split(separators, StringSplitOptions.None);
32 32
33 33 foreach (var item in splitVerse.Select((value, index) => new { index, value }))
34 34 {

DraxCodes's Avatar DraxCodes ревизий этого фрагмента 1753207842. К ревизии

1 file changed, 50 insertions

Program.cs(файл создан)

@@ -0,0 +1,50 @@
1 + public class Program
2 + {
3 + public static void Main()
4 + {
5 + var script = new Scriptures();
6 + var verse = script.GetRandomVerseWithHiddenWords();
7 + Console.WriteLine(verse);
8 + }
9 + }
10 +
11 + public class Scriptures
12 + {
13 + private string[] scripture = new string[]
14 + {
15 + "Mosiah 2:17: And behold, I tell you these things that ye may learn wisdom; that ye may learn that when ye are in the service of your fellow beings ye are only in the service of your God.",
16 + "1 Nephi 3:7: And it came to pass that I, Nephi said unto my father: I will go and do the things which the Lord hath commanded..."
17 + };
18 + string[] separators = new string[] { " " };
19 +
20 + private string GetRandomScripture()
21 + {
22 + var rand = new Random();
23 + int index = rand.Next(scripture.Length);
24 + return scripture[index];
25 + }
26 +
27 + public string GetRandomVerseWithHiddenWords()
28 + {
29 + var selectedScipture = GetRandomScripture();
30 + string[] outPutverse = new string[selectedScipture.Length];
31 + var splitVerse = selectedScipture.Split(" ", StringSplitOptions.None);
32 +
33 + foreach (var item in splitVerse.Select((value, index) => new { index, value }))
34 + {
35 + var rand = new Random();
36 + var tempValue = rand.Next(0, 20);
37 + if (tempValue % 4 == 0)
38 + {
39 + var hiddenWord = new string('_', item.value.Length);
40 + outPutverse[item.index] = hiddenWord + " ";
41 + }
42 + else
43 + {
44 + outPutverse[item.index] = item.value + " ";
45 + }
46 + }
47 +
48 + return string.Concat(outPutverse);
49 + }
50 + }
Новее Позже