static void Main(string[] args) { string phrase; if (args.Length == 0) { Console.WriteLine("Enter a phrase"); phrase = Console.ReadLine(); } else { if (!File.Exists(args[0])) { Console.WriteLine("Enter a valid file name"); return; } phrase = File.ReadAllText(args[0]); } CharacterCount counter = new CharacterCount(); counter.ParseString(phrase); foreach (var letter in Alphabet) { Console.WriteLine("{0} : {1}", letter, counter.GetCountForLetter(letter)); } Console.WriteLine("Press any key to continue..."); phrase = Console.ReadLine(); }
public void ShouldReturnCorrectCountIfStringContainsOneWord() { OrderedDictionary characterCount = CharacterCount.CountCharacters("Apple"); Assert.AreEqual(1, characterCount["A"]); Assert.AreEqual(2, characterCount["p"]); Assert.AreEqual(1, characterCount["l"]); Assert.AreEqual(1, characterCount["e"]); }
public void AddCharacter(GameObject character, Sprite img) { CharacterCount cc = new CharacterCount(); cc.characterPrefab = character; cc.count = 0; cc.image = img; characters.Add(cc); ccc.RenderCharacters(); }
public void CharacterCountAlgTest() { //Arrange var sut = new CharacterCount(); var myString = "Bat"; var expected = "B = 1\na = 1\nt = 1\n"; //Act var result = sut.CharacterCountAlg(myString); //Assert Assert.That(result, Is.EqualTo(expected)); }
public void CharacterCountAlgTest() { //Arrange var sut = new CharacterCount(); var myString = "B"; string expected = "B = 1"; //Act string result = sut.CharacterCountAlg(myString); //Assert Assert.That(result, Is.EqualTo(expected)); }
public void ShouldReturnCorrectCountIfStringContainsOneSentence() { OrderedDictionary characterCount = CharacterCount.CountCharacters("Hello hari!!"); Assert.AreEqual(1, characterCount["H"]); Assert.AreEqual(1, characterCount["e"]); Assert.AreEqual(2, characterCount["l"]); Assert.AreEqual(1, characterCount["o"]); Assert.AreEqual(1, characterCount["h"]); Assert.AreEqual(1, characterCount["a"]); Assert.AreEqual(1, characterCount["r"]); Assert.AreEqual(1, characterCount["i"]); Assert.AreEqual(2, characterCount["!"]); }
public static void Main() { CharacterCount greet = new CharacterCount(); Console.WriteLine("What is the input string?"); string str = Console.ReadLine(); while (str.Length == 0) { Console.WriteLine("You entered an empty string. What is the input string?"); str = Console.ReadLine(); } int numChars = str.Length; Console.WriteLine(str + " has " + numChars + " characters."); }
private void AddWhitespace(char whitespaceType) { if (_currentCharacterCount.Type == whitespaceType) { _currentCharacterCount.Count++; } else { if (_whitespaceCounts == null) { _whitespaceCounts = new Queue <CharacterCount>(); } _whitespaceCounts.Enqueue(_currentCharacterCount); _currentCharacterCount = new CharacterCount(whitespaceType); } }
void ReleaseDesignerOutlets() { if (LabelComposeMessage != null) { LabelComposeMessage.Dispose(); LabelComposeMessage = null; } if (Message != null) { Message.Dispose(); Message = null; } if (LabelUseMagicExpression != null) { LabelUseMagicExpression.Dispose(); LabelUseMagicExpression = null; } if (CharacterCount != null) { CharacterCount.Dispose(); CharacterCount = null; } if (LabelMaxContact != null) { LabelMaxContact.Dispose(); LabelMaxContact = null; } if (MaskButton != null) { MaskButton.Dispose(); MaskButton = null; } if (SendButton != null) { SendButton.Dispose(); SendButton = null; } if (Slider != null) { Slider.Dispose(); Slider = null; } if (SliderCount != null) { SliderCount.Dispose(); SliderCount = null; } if (MagicExpressionSwitch != null) { MagicExpressionSwitch.Dispose(); MagicExpressionSwitch = null; } }
public ConvertStatus ConvertData(ReadOnlySpan <char> inputData, int inputIndex, int inputCount, Span <byte> outputData, int outputIndex, int outputCount, bool flush, out int inputUsed, out int outputUsed) { int inputEnd = inputIndex + inputCount; int outputEnd = outputIndex + outputCount; inputUsed = outputUsed = 0; while (true) { switch (_currentState) { case State.Reset: Reset(); goto case State.PassThrough; case State.BeginPassThrough: _currentState = State.PassThrough; goto case State.PassThrough; case State.PassThrough: while (inputIndex < inputEnd) { char inputChar = inputData[inputIndex]; byte inputType = (inputChar < 128) ? _decodingTable[inputChar] : SettingsCharacterTypes.CharSafeInvalid; if ((inputType & SettingsCharacterTypes.CharSafe) != 0) { // whitespace must be handled separately.. if ((inputChar == ' ') || (inputChar == '\t')) { goto case State.BeginReadLinearWhiteSpace; } if (outputIndex == outputEnd) { return(ConvertStatus.OutputRequired); } // input character is safe, goes directly to output data.. outputData[outputIndex++] = (byte)inputChar; inputIndex++; inputUsed++; outputUsed++; continue; } if (inputChar == '=') { goto case State.BeginEscape; } if (inputChar == '\r') { goto case State.BeginHardBreak; } if ((inputChar == '\n') && ((_flags & SettingsFlags.FlagQpAcceptLFOnlyHardBreaks) != 0)) { // consume LF and write hard break.. inputIndex++; inputUsed++; goto case State.BeginWriteHardBreak; } // fail if we're not ignoring invalid characters.. if ((_flags & SettingsFlags.FlagIgnoreInvalidCharacters) == 0) { throw new FormatException(Resources.DecoderGenericInvalidCharacter); } } if (flush) { goto case State.Finished; } return(ConvertStatus.InputRequired); case State.BeginReadLinearWhiteSpace: _currentCharacterCount = new CharacterCount(inputData[inputIndex++]); _currentState = State.ReadLinearWhiteSpace; inputUsed++; goto case State.ReadLinearWhiteSpace; case State.ReadLinearWhiteSpace: while (inputIndex < inputEnd) { char inputChar = inputData[inputIndex]; if ((inputChar == ' ') || (inputChar == '\t')) { AddWhitespace(inputChar); inputIndex++; inputUsed++; continue; } // whitespace followed by anything other than a CR is important.. if (inputChar != '\r') { goto case State.BeginWriteLinearWhiteSpace; } // return to pass through state to handle this character.. goto case State.BeginPassThrough; } if (flush) { goto case State.BeginWriteLinearWhiteSpace; } return(ConvertStatus.InputRequired); case State.BeginWriteLinearWhiteSpace: if ((_whitespaceCounts != null) && (_whitespaceCounts.Count > 0)) { _whitespaceCounts.Enqueue(_currentCharacterCount); _currentCharacterCount = _whitespaceCounts.Dequeue(); } _currentState = State.WriteLinearWhiteSpace; goto case State.WriteLinearWhiteSpace; case State.WriteLinearWhiteSpace: while (outputIndex < outputEnd) { byte charValue = (byte)_currentCharacterCount.Type; int whiteToWrite = Math.Min(outputEnd - outputIndex, _currentCharacterCount.Count); for (int iIndex = outputIndex; iIndex < outputIndex + whiteToWrite; iIndex++) { outputData[iIndex] = charValue; } outputIndex += whiteToWrite; outputUsed += whiteToWrite; if ((_currentCharacterCount.Count -= whiteToWrite) == 0) { if ((_whitespaceCounts != null) && (_whitespaceCounts.Count > 0)) { _currentCharacterCount = _whitespaceCounts.Dequeue(); } else { // done writing whitespace, return to the pass through state.. goto case State.BeginPassThrough; } } } return(ConvertStatus.OutputRequired); case State.BeginHardBreak: inputIndex++; inputUsed++; _currentState = State.HardBreak; goto case State.HardBreak; case State.HardBreak: if (inputIndex < inputEnd) { if (inputData[inputIndex] == '\n') { // formal hard break, consume the LF character.. inputIndex++; inputUsed++; } else if ((_flags & SettingsFlags.FlagQpAcceptCROnlyHardBreaks) == 0) { // CR not followed by LF and we're not accepting CR only as a break.. if ((_flags & SettingsFlags.FlagIgnoreInvalidCharacters) == 0) { throw new FormatException(Resources.DecoderGenericInvalidCharacter); } // ignore the CR and process the current character.. goto case State.BeginPassThrough; } // hard break read, write out the hard break value goto case State.BeginWriteHardBreak; } if (flush) { if ((_flags & SettingsFlags.FlagQpAcceptCROnlyHardBreaks) == 0) { if ((_flags & SettingsFlags.FlagIgnoreInvalidCharacters) == 0) { throw new FormatException(Resources.DecoderGenericInvalidCharacter); } // ignore the CR, goto Finished state.. goto case State.Finished; } // treat CR as formal hard break.. goto case State.BeginWriteHardBreak; } return(ConvertStatus.InputRequired); case State.BeginWriteHardBreak: _currentOffset = 0; _currentState = State.WriteHardBreak; goto case State.WriteHardBreak; case State.WriteHardBreak: while ((_currentOffset < _hardBreakBytes.Length) && (outputIndex < outputEnd)) { outputData[outputIndex++] = (byte)_hardBreakBytes[_currentOffset++]; outputUsed++; } if (_currentOffset == _hardBreakBytes.Length) { goto case State.BeginPassThrough; } return(ConvertStatus.OutputRequired); case State.BeginEscape: inputIndex++; inputUsed++; _currentByte = 0; _currentState = State.Escape; goto case State.Escape; case State.Escape: if (inputIndex < inputEnd) { char inputChar = inputData[inputIndex]; if (inputChar == '\r') { goto case State.BeginSoftBreak; } if ((inputChar == '\n') && ((_flags & SettingsFlags.FlagQpAcceptLFOnlyHardBreaks) != 0)) { // soft-break in form "=\n" .. inputIndex++; inputUsed++; // escape complete, continue processing.. goto case State.BeginPassThrough; } int inputType = (inputChar < 128) ? _hexDecodingTable[inputChar] : SettingsCharacterTypes.CharSpecialInvalid; if (inputType == SettingsCharacterTypes.CharSpecialInvalid) { if ((_flags & SettingsFlags.FlagIgnoreInvalidCharacters) == 0) { throw new FormatException(Resources.DecoderGenericInvalidCharacter); } // ignoring invalid characters, just skip the equal.. goto case State.BeginPassThrough; } // consume character and continue to second escape character.. inputIndex++; inputUsed++; _currentByte = (byte)inputType; goto case State.BeginContinueEscape; } if (flush) { // equal with nothing following is invalid.. if ((_flags & SettingsFlags.FlagIgnoreInvalidCharacters) == 0) { throw new FormatException(Resources.DecoderGenericInvalidCharacter); } // ignore it, .. goto case State.Finished; } return(ConvertStatus.InputRequired); case State.BeginContinueEscape: _currentState = State.ContinueEscape; goto case State.ContinueEscape; case State.ContinueEscape: if (inputIndex < inputEnd) { char inputChar = inputData[inputIndex]; int inputValue = (inputChar < 128) ? _hexDecodingTable[inputChar] : SettingsCharacterTypes.CharSpecialInvalid; if (inputValue == SettingsCharacterTypes.CharSpecialInvalid) { if ((_flags & SettingsFlags.FlagIgnoreInvalidCharacters) == 0) { throw new FormatException(Resources.DecoderGenericInvalidCharacter); } // ignore partial escape.. goto case State.BeginPassThrough; } inputIndex++; inputUsed++; _currentByte = (byte)((_currentByte << 4) | (byte)(inputValue)); goto case State.BeginWritingEscape; } if (flush) { if ((_flags & SettingsFlags.FlagIgnoreInvalidCharacters) == 0) { throw new FormatException(Resources.DecoderGenericInvalidCharacter); } // partial escape is invalid, ignore the entire thing.. goto case State.Finished; } return(ConvertStatus.InputRequired); case State.BeginWritingEscape: _currentState = State.WritingEscape; goto case State.WritingEscape; case State.WritingEscape: if (outputIndex < outputEnd) { outputData[outputIndex++] = _currentByte; outputUsed++; goto case State.BeginPassThrough; } return(ConvertStatus.OutputRequired); case State.BeginSoftBreak: inputIndex++; inputUsed++; _currentState = State.SoftBreak; goto case State.SoftBreak; case State.SoftBreak: if (inputIndex < inputEnd) { int inputChar = inputData[inputIndex]; if (inputChar == '\n') { inputIndex++; inputUsed++; } else if ((_flags & SettingsFlags.FlagQpAcceptCROnlyHardBreaks) == 0) { if ((_flags & SettingsFlags.FlagIgnoreInvalidCharacters) == 0) { throw new FormatException(Resources.DecoderGenericInvalidCharacter); } } goto case State.BeginPassThrough; } if (flush) { if (((_flags & SettingsFlags.FlagQpAcceptCROnlyHardBreaks) == 0) && ((_flags & SettingsFlags.FlagIgnoreInvalidCharacters) == 0)) { throw new FormatException(Resources.DecoderGenericInvalidCharacter); } // ignore the CR, goto Finished state.. goto case State.Finished; } return(ConvertStatus.InputRequired); case State.Finished: _currentState = State.Reset; return(ConvertStatus.Complete); case State.ReturnToPreviousState: System.Diagnostics.Debug.Assert(_previousState != State.ReturnToPreviousState); _currentState = _previousState; _previousState = State.ReturnToPreviousState; continue; } throw new InvalidOperationException("Unreachable code, reached."); } }
public SongDetails(int song_id) { InitializeComponent(); using (var session = NHibernateHelper.OpenSession()) { Binding b = new Binding(); b.Source = CommentTextBox; b.Path = new PropertyPath("Text.Length"); b.Mode = BindingMode.OneWay; CharacterCount.SetBinding(TextBlock.TextProperty, b); song = db.GetSong(song_id, session); SongTitle.Content = song.Title; AlbumName.Content = song.Albums_Id?.Title; string s = "by "; foreach (Artists g in song.artists) { s += g.Name + ", "; } ArtistName.Content = s.Substring(0, s.Length - 2); if (song.genres.Count != 0) { s = ""; foreach (Genres g in song.genres) { s += g.Name + ", "; } Genre.Content = s.Substring(0, s.Length - 2); } List <Ratings> r = db.GetSongRatings(song, session); NumberOfRatings.Text = "(" + r.Count.ToString() + ")"; if (r.Count != 0) { decimal score = 0; foreach (Ratings rating in r) { score += rating.Value; } score /= r.Count; AverageScore.Text = score.ToString("#.##"); } List <Comments> comments = db.GetSongComments(song, session); if (comments.Count != 0) { NoCommentsBlock.Visibility = Visibility.Collapsed; foreach (Comments c in comments) { s = c.Users_Id.Username + " " + c.Post_date.ToString().Substring(0, 10) + "\n" + c.Content; CommentsList.Items.Add(s); } } ratingFromDb = db.GetYourRating(song, session); if (ratingFromDb != null) { switch (ratingFromDb.Value) { case (1): Rating.CheckBox1.IsChecked = true; break; case (2): Rating.CheckBox1.IsChecked = true; Rating.CheckBox2.IsChecked = true; break; case (3): Rating.CheckBox1.IsChecked = true; Rating.CheckBox2.IsChecked = true; Rating.CheckBox3.IsChecked = true; break; case (4): Rating.CheckBox1.IsChecked = true; Rating.CheckBox2.IsChecked = true; Rating.CheckBox3.IsChecked = true; Rating.CheckBox4.IsChecked = true; break; case (5): Rating.CheckBox1.IsChecked = true; Rating.CheckBox2.IsChecked = true; Rating.CheckBox3.IsChecked = true; Rating.CheckBox4.IsChecked = true; Rating.CheckBox5.IsChecked = true; break; } } } }
public void ShouldReturnEmptyMapIfStringContainsOnlySpaces() { OrderedDictionary characterCount = CharacterCount.CountCharacters(" "); Assert.AreEqual(0, characterCount.Count); }
public void ShouldReturnCorrectCountIfStringContainsOneCharacter() { OrderedDictionary characterCount = CharacterCount.CountCharacters("T"); Assert.AreEqual(1, characterCount["T"]); }
public void ShouldReturnEmptyMapIfStringIsEmpty() { OrderedDictionary characterDictionary = CharacterCount.CountCharacters(""); Assert.AreEqual(0, characterDictionary.Count); }
static void Main(string[] args) { int active = 0; do { Console.WriteLine("Vilket programm? A,B,C,D,E,F,H,I eller Q för att avsluta?"); String choice = Console.ReadLine(); String Change = choice.ToLower(); switch (Change) { case "a": System.Console.WriteLine("Skriv in en mening"); System.String quote = Console.ReadLine(); System.String wordd = quote; wordd = System.Text.RegularExpressions.Regex.Replace(quote, @"\s+", " "); int countWords = wordd.Trim().Split().Length; System.Console.WriteLine("Din mening innehåller " + countWords + " ord."); string[] words = quote.Split(' '); foreach (string word in words) { Console.WriteLine(word + " är " + word.Length + " tecken"); } active = 1; break; case "b": System.Console.WriteLine("Skriv en mening"); String text = Console.ReadLine(); words = text.Split(' '); Array.Sort(words, (x, y) => x.Length.CompareTo(y.Length)); Array.Reverse(words); for (int i = 0; i < words.Length; i++) { Console.WriteLine(words[i]); } Console.WriteLine(" "); Array.Reverse(words); for (int i = 0; i < words.Length; i++) { Console.WriteLine(words[i]); } Console.ReadLine(); active = 1; break; case "c": System.Console.WriteLine("Skriv en mening"); String sentence = Console.ReadLine(); string txt = sentence.ToLower(); String[] part = txt.Split(' ', ',', '?', '!'); var list = new List <string>(part); var q = list.GroupBy(b => b) .Select(g => new { Value = g.Key, Count = g.Count() }) .OrderByDescending(b => b.Count); foreach (var b in q) { Console.WriteLine("Ord: " + b.Value + " Antal: " + b.Count); } active = 1; break; case "d": System.Console.WriteLine("Skriv en mening"); String line = Console.ReadLine(); string parts = line.ToLower(); String[] myStrings = line.Split(); string longText = line; var count = CharacterCount.Count(longText); foreach (var character in count) { Console.WriteLine("{0} - {1}", character.Key, character.Value); } active = 1; break; case "e": int k = 0; do { System.Console.WriteLine("Skriv in ett ord, skriv in 'avsluta' för att avsluta "); String input = Console.ReadLine(); String close = ("avsluta"); int c = string.Compare(input, close); System.Console.WriteLine("Du skrev " + input); if (c == 0) { k = 1; } }while (k != 1); active = 1; break; case "f": int l = 0; do { System.Console.WriteLine(" Skriv in siffra mellan 1 och 21. "); int guess = Convert.ToInt32(Console.ReadLine()); Random random = new Random(); int luck = random.Next(1, 21); if (guess == luck) { System.Console.WriteLine("Du gissa rätt! Tillbaka till menyn för ditt pris "); l = 1; } else { System.Console.WriteLine("Du gissa tyvärr fel, försök igen!" + " Rätt siffra var " + luck); l = 0; } ; }while (l != 1); active = 1; break; case "h": string[] stringsForEncoding = { "4", "8", "( ", "|)", "3", "|=", "9", "|-|", "1", "!", "|<", "1", "(V)", "(\\)", "0", "|2", "(,)", "|Z", "5", "7", "|_|", "\\/", "`//", "x", "y", "z" }; string[] alphabet = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; Console.Write("Skriv vad vill du översätta till LEET: "); char[] toLeet = Console.ReadLine().ToCharArray(); int length = toLeet.Length; string[] encodedCharacters = new string[length]; int leet = 0; foreach (char normal in toLeet) { if ((normal >= 'a' && normal <= 'z') || (normal >= 'A' && normal <= 'Z')) { int results = Array.FindIndex(alphabet, x => x.Contains(normal)); encodedCharacters[leet] = stringsForEncoding[results]; } else { encodedCharacters[leet] = normal.ToString(); } leet++; } Console.WriteLine(string.Join("", encodedCharacters)); active = 1; break; case "i": active = 1; break; System.Console.ReadLine(); case "q": Application.Exit(); active = 0; break; } }while (active != 0); }