// 加密 public String EncryptCode(String number) { char[] arrStr = number.ToArray(); for (int i = 0; i < arrStr.Length; i++) { arrStr[i] = (char)((arrStr[i] - 41) % 10 + 48); } return new String(arrStr); }
public static int StringScore(String s) { int sum = 0; foreach (var c in s.ToArray()) { sum += (int)(c - 64); } return sum; }
//Method to reverse the order of the characters in strings. public static String reverseString(String s) { //Change string to character array char[] reverse = s.ToArray(); //Reverse the array Array.Reverse(reverse); //Return reversed array as string return new String(reverse); }
//Une Fonction pour chiffrer et Déchiffrer public static String ChiffrerDechiffrer(String str, int Value) { //Tableau char utiliser pour faire le ou sur chaque lettre ou chiffre Char[] carry = str.ToArray(); //Boucle qui applique le ou exclusife sur chaque character for (int i = 0; i < str.Length; i++) { carry[i] ^= (char)Value; } return new string(carry); }
public static String reverseNumber(String number) { char[] numberAsArray = number.ToArray(); int numberLength = numberAsArray.Length - 1; String reverseNumber = null; for(int i = numberLength; i >= 0; i--){ reverseNumber += numberAsArray[i]; } return reverseNumber; }
//method 4: sort string first, then check 2 neighbour chars if same static bool isUnique_withSort(String s) { if (s.Length > 128) return false; Array charArray = s.ToArray<Char>(); Array.Sort(charArray); StringBuilder sb = new StringBuilder(); foreach (Char c in charArray) { sb.Append(c); } s = sb.ToString(); for (int i = 0; i < (s.Length-1); i++) { if (s[i] == s[i + 1]) return false; } return true; }
private static StringBuilder convertToUnicode(String regText) { char[] chars = regText.ToArray(); StringBuilder hexString = new StringBuilder(); for (int i = 0; i < chars.Length; i++) { String iniHexString = String.Format("{0:X}", chars[i]);// ((int)HexEncoding.GetByteCount((int)chars[i])).ToString(); if (iniHexString.Length == 1) iniHexString = "000" + iniHexString; else if (iniHexString.Length == 2) iniHexString = "00" + iniHexString; else if (iniHexString.Length == 3) iniHexString = "0" + iniHexString; hexString.Append(iniHexString); } return hexString; }
public static Boolean isPalindrome(String number) { char[] numberAsArray = number.ToArray(); int arrayLength = numberAsArray.Length; int numberLength = arrayLength-1; double halfOfArrayLength = ((arrayLength) / 2); int halfOfArrayLengthCeilled = (int)Math.Ceiling(halfOfArrayLength); for (int i = 0; i < halfOfArrayLengthCeilled; i++, numberLength--) { if(!isSameNumber(numberAsArray[i], numberAsArray[numberLength])){ return false; } if(isMoreThanHalfChecked(numberLength, i)) { break; } } return true; }
public static IList<InterView> GetInterViews(String[] ids) { try { MongoCursor<InterView> mc = MongoDBHelper.GetCursor<InterView>( "InterView", Query.EQ("_id", new BsonArray(ids.ToArray())), new SortByDocument("CreatedTime", 1), 0, 0); List<InterView> objs = new List<InterView>(); objs.AddRange(mc); return objs; } catch (System.Exception err) { throw new CBB.ExceptionHelper.OperationException( CBB.ExceptionHelper.ErrType.SystemErr, CBB.ExceptionHelper.ErrNo.DBOperationError, err); } }
private void AddUser_Click(object sender, RoutedEventArgs e) { // Username String username = _Username.GetLineText(0); // Email String email = _Email.GetLineText(0); // Home String home = _Home.GetLineText(0); // list? Read? Write? Delete? Boolean list = (Boolean)_List.IsChecked; Boolean read = (Boolean)_Read.IsChecked; Boolean write = (Boolean)_Write.IsChecked; Boolean delete = (Boolean)_Delete.IsChecked; // Password String password = _Password.GetLineText(0); // Name String name = _Name.GetLineText(0); // Role String role; try { role = _Role.SelectedValue.ToString(); } catch (Exception) { role = "null"; } // Expiration String expiration = _Expiration.GetLineText(0); // Groups String[] groups; try { groups = new String[_GroupRemove.Items.Count]; int j = 0; foreach (ItemCollection i in _GroupRemove.Items) { groups[j] = i.ToString(); j++; } } catch (Exception) { groups = null; } MessageBox.Show(String.Format("Username:{0}\nEmail:{1}\nHome:{2}\nList:{3}\nRead:{4}\nWrite:{5}\nDelete:{6}\nPassword:{7}\nName:{8}\nRole:{9}\nExpiration:{10}\nGroups:{11}\n", username, email, home, list, read, write , delete, password, name, role, expiration, groups.ToArray<String>().ToString())); this.Close(); }
/// <summary> /// /// </summary> private void SetupSeps() { // seps should contain only characters present in alphabet; seps = new String(seps.Intersect(alphabet.ToArray()).ToArray()); // alphabet should not contain seps. alphabet = new String(alphabet.Except(seps.ToArray()).ToArray()); seps = ConsistentShuffle(seps, salt); if (seps.Length == 0 || (alphabet.Length / seps.Length) > SEP_DIV) { var sepsLength = (int)Math.Ceiling(alphabet.Length / SEP_DIV); if (sepsLength == 1) sepsLength = 2; if (sepsLength > seps.Length) { var diff = sepsLength - seps.Length; seps += alphabet.Substring(0, diff); alphabet = alphabet.Substring(diff); } else seps = seps.Substring(0, sepsLength); } sepsRegex = new Regex(string.Concat("[", seps, "]"), RegexOptions.Compiled); alphabet = ConsistentShuffle(alphabet, salt); }
//Creates hexadecimal color from sequence private Brush convertColorFromSeq(String s) { try { if (s.All(c => "actg".Contains(c))) { String color = "#"; char[] array = s.ToArray(); for (int i = 0; i < 4; i++) { char c = char.ToLower(array[i]); if (c == 'a') color += "99"; if (c == 'c') color += "bb"; if (c == 't') color += "dd"; if (c == 'g') color += "ff"; } return (Brush)new BrushConverter().ConvertFromString(color); //To always ensure Opacity = 1, use i < 3 and initialize color = "#ff" } else { return Brushes.LightGray; } } catch (Exception exc) { Console.WriteLine(exc); return Brushes.LightGray; } }
// var x = db.test().find().clone(...) // will return index just after 'find()' // where clone is the method name, and find() is the parent method private static int GetMethodIndex(Match firstBracket, String query, out bool hasParent) { //var word = new List<char>(); var chars = query.ToArray<char>(); hasParent = false; int i; for (i = firstBracket.Index - 1; i > -1; i--) { var c = chars[i]; if (c == ']' || c == '}' || c == ')') { hasParent = true; return i + 1; } if (Char.IsLetter(c) || Char.IsNumber(c) || Char.IsWhiteSpace(c) || c == '.' || c == '_') { continue; } else { break; } } return i + 1; }
/// <summary> /// 按兴趣编号数组获取兴趣问问按指定字段排序 /// </summary> /// <param name="interestsids">兴趣编号数组</param> /// <param name="sortByField">排序字段</param> /// <param name="lift">升或降序</param> /// <param name="pagesize">每页条数</param> /// <param name="pageno">当前页</param> /// <returns></returns> private static IList<WenWen> GetInterestIdArrWenWenSorted(String[] interestsids, String sortByField, int lift, int pagesize, int pageno) { MongoCursor<WenWen> mc = MongoDBHelper.GetCursor<WenWen>(WenWen.GetCollectionName(), Query.In("InterestID", new BsonArray(interestsids.ToArray())), new SortByDocument(sortByField, lift), pageno, pagesize); List<WenWen> objs = new List<WenWen>(); objs.AddRange(mc); IList<WenWen> wenwens = new List<WenWen>(); foreach (var obj in objs) { obj.AnswerCount = GetWenWenAnswer(obj.ID, 0, 0, 1).Count; wenwens.Add(obj); } return wenwens; }
private static String GetMethodName(Match firstBracket, String s) { var word = new List<char>(); var chars = s.ToArray<char>(); for (int i = firstBracket.Groups[0].Index - 1; i > -1; i--) { var c = chars[i]; if (Char.IsLetter(c) || Char.IsNumber(c) || Char.IsWhiteSpace(c) || c == '.') { word.Add(c); } else { break; } } var Word = new StringBuilder(); word.Reverse(); word.ForEach(x => Word.Append(x.ToString())); return Word.ToString().Trim(); }
public void TestGetCPRsFromArrayOfobjectIDsWithNullValues([ValueSource("CprCounts")] int count) { var cprNumbers = new String[count]; PersonMasterServiceLibrary.BasicOpClient client = new PersonMasterServiceLibrary.BasicOpClient(); string aux = null; var ret = client.GetCPRsFromObjectIDArray("", cprNumbers.ToArray(), ref aux); Assert.NotNull(aux, "Aux is null"); Assert.AreEqual(count, ret.Length); }