/// <summary> /// 生成一个有序的string /// </summary> /// <returns></returns> public static string GenerateString(StringLength length) { if (length == StringLength.L30) { return(StringGerarator.Generate30()); } return(StringGerarator.Generate24()); }
/// <summary> /// 生成纯数字数据 /// </summary> /// <returns></returns> public static string GenerateNumber(StringLength length) { if (length == StringLength.L30) { return(NumberGenrator.Generate30()); } return(NumberGenrator.Generate24()); }
public void Dispose() { TextInput?.Dispose(); FirstCharacter?.Dispose(); StringLength?.Dispose(); StringLengthLabel?.Dispose(); FirstCharacterLabel?.Dispose(); TimeOnPage?.Dispose(); TimeOnPageLabel?.Dispose(); }
public ReactiveSampleViewModel() { TextInput = new ReactiveProperty <string>(""); FirstCharacter = TextInput.Select(x => x.ToCharArray()).Select(x => x.Any() ? (char?)x.First() : null).ToReadOnlyReactiveProperty(); FirstCharacterLabel = FirstCharacter.Select(x => x != null ? $"The first character is {x.ToString()}" : "There is no first character!").ToReadOnlyReactiveProperty(); StringLength = TextInput.Select(x => x.Length).ToReadOnlyReactiveProperty(); StringLengthLabel = StringLength.Select(x => $"The string is {x} character{(x != 1 ? "s" : "")} long.").ToReadOnlyReactiveProperty(); var timePageLoaded = DateTime.Now; TimeOnPage = Observable.Interval(TimeSpan.FromSeconds(1)).Select(x => DateTime.Now.Subtract(timePageLoaded)).ToReadOnlyReactiveProperty(); TimeOnPageLabel = TimeOnPage.Select(x => (int)x.TotalSeconds).Select(x => $"You've been on this page for {x} second{(x != 1 ? "s" : "")}.").ToReadOnlyReactiveProperty(); }
public static int Main() { StringLength sl = new StringLength(); TestLibrary.TestFramework.BeginTestCase("StringLength"); if (sl.RunTests()) { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("PASS"); return 100; } else { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("FAIL"); return 0; } }
public static int Main() { StringLength sl = new StringLength(); TestLibrary.TestFramework.BeginTestCase("StringLength"); if (sl.RunTests()) { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("PASS"); return(100); } else { TestLibrary.TestFramework.EndTestCase(); TestLibrary.TestFramework.LogInformation("FAIL"); return(0); } }
/// <summary> /// Validates the length of the given string for the given type. /// </summary> /// <param name="stringToValidate"> String to be validated. </param> /// <param name="stringTypeLength"> Length type of the string. </param> /// <returns> True if the string length of the given string is valid for given type length. </returns> public static bool ValidateLength(string stringToValidate, StringLength stringTypeLength) { if (null == stringToValidate) { ExceptionManager.Throw(new ArgumentNullException()); } int length = stringToValidate.Length; if (stringTypeLength != StringLength.Other) { if (length == 0) { ExceptionManager.Throw(new InvalidLengthException()); } else if (length > (int) stringTypeLength) { ExceptionManager.Throw(new TooLongStringException()); } } return true; }
/// <summary> /// Validates the length of the given string for the given type. /// </summary> /// <param name="stringToValidate"> String to be validated. </param> /// <param name="stringTypeLength"> Length type of the string. </param> /// <returns> True if the string length of the given string is valid for given type length. </returns> public static bool ValidateLength(string stringToValidate, StringLength stringTypeLength) { if (null == stringToValidate) { ExceptionManager.Throw(new ArgumentNullException()); } int length = stringToValidate.Length; if (stringTypeLength != StringLength.Other) { if (length == 0) { ExceptionManager.Throw(new InvalidLengthException()); } else if (length > (int)stringTypeLength) { ExceptionManager.Throw(new TooLongStringException()); } } return(true); }
public MustBeAttribute(StringLength stringLength, int value) { StringLength = stringLength; Value = value; }
// input vào là các giá trị của Post output là các giá trị của PostItemModel public static PostItemModel Convert( this Post post, bool withFullDesc = true, bool withUser = false, bool withTag = false, string catURL = null ) { var _return = new PostItemModel() { Id = post.Id, URL = post.URL, CreateDate = post.StartDate ?? post.CreateDate, View = post.View }; if (!string.IsNullOrEmpty(post.ImageURL)) { try { _return.ImageURL = JsonConvert.DeserializeObject <ImageURLModel>(post.ImageURL); } catch (Exception ex) { } } var cat = post.Categories.FirstOrDefault(c => (string.IsNullOrEmpty(catURL) ? true : c.URL.CompareTo(catURL) == 0) && !c.IsDeleted && c.IsShow ); if (cat != null) { _return.Category = Convert(cat); } if (withFullDesc) { _return.Title = post.Title; _return.ShortDesc = post.ShortDesc; _return.FullDesc = post.FullDesc; _return.SeoTitle = post.SeoTitle; _return.SeoKeyword = post.SeoKeyword; _return.SeoDescription = post.SeoDescription; } else { _return.Title = post.Title; _return.ShortDesc = StringLength.TrimLenght(post.ShortDesc, 150);//HttpUtility.HtmlDecode(Utility.TrimLength(FPTShopUtils.RemoveHTMLTag((post.ShortDesc)), 220)); } if (withUser) { _return.User = Convert(post.CreateUser, withDescription: withFullDesc); } if (withTag) { if (post.Tags.Any()) { _return.Tags = Convert(post.Tags.ToList()); } } return(_return); }
// Update all string stats for which there are enough strings entered. private void computeStatsButton_Click(object sender, EventArgs e) { TabPage selectedTab = statsTabControl.SelectedTab; bool isInput1Empty = (inputTextBox1.Text == String.Empty); bool isInput2Empty = (inputTextBox2.Text == String.Empty); bool isInput3Empty = (inputTextBox3.Text == String.Empty); bool isInput1Error = false; // isInput1Empty; bool isInput2Error = false; // isInput2Empty && (selectedTab == tabPage2 || selectedTab == tabPage3); bool isInput3Error = false; // isInput3Empty && selectedTab == tabPage3; bool isInputError = isInput1Error || isInput2Error || isInput3Error; inputValidatorTextBox1.Text = isInput1Error ? "String #1 must be non-empty for all stats" : String.Empty; inputValidatorTextBox2.Text = isInput2Error ? "String #2 must be non-empty for 1-string and 2-string stats" : String.Empty; inputValidatorTextBox3.Text = isInput3Error ? "String #3 must be non-empty for 3-string stats" : String.Empty; inputValidatorTextBox1.Visible = isInput1Error; inputValidatorTextBox2.Visible = isInput2Error; inputValidatorTextBox3.Visible = isInput3Error; inputValidatorTextBox.Visible = isInputError; if (isInputError) { int numErrors = (isInput1Error ? 1 : 0) + (isInput2Error ? 1 : 0) + (isInput3Error ? 1 : 0); inputValidatorTextBox.Text = String.Format( "Please fix the {0} error{1} above before continuing.", numErrors, numErrors == 1 ? String.Empty : "s" ); return; } inputValidatorTextBox.Text = String.Empty; // One String stringLengthTextBox.Text = Convert.ToString( StringLength.Length(inputTextBox1.Text) ); List <string> palindromes = Palindrome.LongestPalindromes(inputTextBox1.Text); longestPalindromesTextBox.Text = String.Join(Environment.NewLine, palindromes); // Two Strings levenshteinTextBox.Text = Convert.ToString( StringDistance.LevenshteinDistance(inputTextBox1.Text, inputTextBox2.Text) ); damerauLevenshteinTextBox.Text = Convert.ToString( StringDistance.DamerauLevenshteinDistance(inputTextBox1.Text, inputTextBox2.Text) ); optimalStringAlignmentTextBox.Text = Convert.ToString( StringDistance.OptimalStringAlignmentDistance(inputTextBox1.Text, inputTextBox2.Text) ); longestCommonSubsequencesTextBox.Text = String.Join(Environment.NewLine, CommonSubset.LongestCommonSubsequences(inputTextBox1.Text, inputTextBox2.Text) ); longestCommonSubstringsTextBox.Text = String.Join(Environment.NewLine, CommonSubset.LongestCommonSubstrings(inputTextBox1.Text, inputTextBox2.Text) ); }
public void String_Lenght() { Assert.Equal(10, StringLength.CountString("Hello World")); }
public static string Process(string input1, string input2, string input3) { string output = string.Empty; switch (input3) { case "add": output = Addition.Add(input1, input2).ToString(); break; case "subtraction": output = Subtraction.Sub(input1, input2).ToString(); break; case "multiplication": output = Multiplication.Mul(input1, input2).ToString(); break; case "division": output = Division.Div(input1, input2).ToString(); break; case "divby3notby6": output = Divisionbythreenotbysix.Run(input1).ToString(); break; case "armstrongornot": output = Armstrongnumber.Check(input1).ToString(); break; case "factorial": output = Factorial.Calculate(input1).ToString(); break; case "palindrome": output = PalindromeNumber.Find(input1).ToString(); break; case "reverse": output = ReverseNumber.Reverse(input1).ToString(); break; case "sumofdigits": output = Sumofdigits.Find(input1).ToString(); break; case "decimaltobinary": output = DecimaltoBinary.Converts(input1).ToString(); break; case "numberincharacter": output = NumbersInCharacters.Print(input1).ToString(); break; case "strreverse": output = StringReverse.Reverse(input1).ToString(); break; case "duplicate": output = DuplicateElement.Find(input1).ToString(); break; case "unique": output = UniqueElement.Return(input1).ToString(); break; case "strpalindrome": output = StringPalindrome.Find(input1).ToString(); break; case "length": output = StringLength.Calculate(input1).ToString(); break; case "vowels": output = NumofVowels.Print(input1).ToString(); break; case "search": output = CharacterSearching.Search(input1, input2).ToString(); break; case "count": output = WordCount.Count(input1).ToString(); break; case "date": output = DateandTime.Calculate(input1).ToString(); break; } return(output); }
public void StringLengthTest() { var sut = new StringLength(new StringConstant("Hello world!")); Assert.AreEqual(12, sut.Value); }