Advertisement
Morogn93

ManipulateString

Feb 6th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. public class ManipulateString
  2.     {
  3.         public bool result { get; private set; }
  4.  
  5.         private char[] StringToChar(string Word)
  6.         {
  7.             char[] myChar = Word.ToCharArray();
  8.  
  9.             //zwraca łancuch znaków w postaci tablicy znaków
  10.             return myChar;
  11.         }
  12.         private int[] CharToAscii(char[] Letter)
  13.         {
  14.             int i = 0;
  15.             int[] temp = new int[Letter.Length];
  16.             while (i < Letter.Length)
  17.             {
  18.                 temp[i] = (int)Letter[i];
  19.                 i++;
  20.             }
  21.  
  22.             //zwraca tablice intow z zawartoscia kodu asci
  23.             return temp;
  24.         }
  25.         private bool[] CheckWordRangeOfAscii(int rangeForm, int rangeTo, int[] valueOfArray)
  26.         {
  27.             bool[] temp = new bool[valueOfArray.Length];
  28.  
  29.             for (int i = 0; i < valueOfArray.Length; i++)
  30.             {
  31.                 if (valueOfArray[i] >= rangeForm && valueOfArray[i] <= rangeTo)
  32.                 {
  33.                     temp[i] = true;
  34.                 }
  35.                 else if (valueOfArray[i] < rangeForm && valueOfArray[i] > rangeTo)
  36.                 {
  37.                     temp[i] = false;
  38.                 }
  39.             }
  40.             return temp;
  41.         }
  42.         public bool CheckTrueCheckFalse(bool[] value)
  43.         {
  44.             bool temp = true;
  45.             for (int i = 0; i < value.Length; i++)
  46.                 if ((value[i] == false))
  47.                 {
  48.                     temp = false;
  49.                 }
  50.  
  51.             return temp;
  52.         }
  53.         /// <summary>
  54.         /// Sprawdza czy podany wyraz znajduje się w podanym przedziale kodu ASCII
  55.         /// </summary>
  56.         /// <param name="rangeFrom">podaj niższą wartość wymaganego ascii</param>
  57.         /// <param name="rangeTo">podaj wyższą wartość wymaganego ascii</param>
  58.         /// <param name="word">podaj słowo które chcesz sprawdzić czy miesci się w przedziale</param>
  59.         public ManipulateString(int rangeFrom, int rangeTo, string word)
  60.         {
  61.           this.result = CheckTrueCheckFalse(CheckWordRangeOfAscii(rangeFrom, rangeTo, (CharToAscii(StringToChar(word)))));
  62.         }
  63.        
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement