PDA

View Full Version : سوال در مورد سرچ با استفاده از BindingSource



mehdi0020
شنبه 11 اسفند 1397, 09:27 صبح
سلام روز بخیر
میخواهم سرچ جوری بنویسم که تک تک کاراکترهای ورودی پیدا کنه
مثلا اگه کاربر بزنه 658 تمام
6 ها و 5 ها و 8 ها و 65 ها و58 ها و 658 ها پیدا کنه
منظورم درست رسوندم؟؟؟؟

ژیار رحیمی
شنبه 11 اسفند 1397, 20:06 عصر
سلام .جهت این جور search ها از regx استفاده میکنند. در مورد regular expression در #c جستجو کنید

alexmcse
شنبه 11 اسفند 1397, 22:54 عصر
مثال

using System;using System.Globalization;
using System.Text.RegularExpressions;


public class Example
{
public static void Main()
{
// Get the current NumberFormatInfo object to build the regular
// expression pattern dynamically.
NumberFormatInfo nfi = NumberFormatInfo.CurrentInfo;


// Define the regular expression pattern.
string pattern;
pattern = @"^\s*[";
// Get the positive and negative sign symbols.
pattern += Regex.Escape(nfi.PositiveSign + nfi.NegativeSign) + @"]?\s?";
// Get the currency symbol.
pattern += Regex.Escape(nfi.CurrencySymbol) + @"?\s?";
// Add integral digits to the pattern.
pattern += @"(\d*";
// Add the decimal separator.
pattern += Regex.Escape(nfi.CurrencyDecimalSeparator) + "?";
// Add the fractional digits.
pattern += @"\d{";
// Determine the number of fractional digits in currency values.
pattern += nfi.CurrencyDecimalDigits.ToString() + "}?){1}$";

Regex rgx = new Regex(pattern);


// Define some test strings.
string[] tests = { "-42", "19.99", "0.001", "100 USD",
".34", "0.34", "1,052.21", "$10.62",
"+1.43", "-$0.23" };


// Check each test string against the regular expression.
foreach (string test in tests)
{
if (rgx.IsMatch(test))
Console.WriteLine("{0} is a currency value.", test);
else
Console.WriteLine("{0} is not a currency value.", test);
}
}
}
// The example displays the following output:
// -42 is a currency value.
// 19.99 is a currency value.
// 0.001 is not a currency value.
// 100 USD is not a currency value.
// .34 is a currency value.
// 0.34 is a currency value.
// 1,052.21 is not a currency value.
// $10.62 is a currency value.
// +1.43 is a currency value.
// -$0.23 is a currency value.

mehdi0020
دوشنبه 13 اسفند 1397, 07:05 صبح
s
مثال

using System;using System.Globalization;
using System.Text.RegularExpressions;


public class Example
{
public static void Main()
{
// Get the current NumberFormatInfo object to build the regular
// expression pattern dynamically.
NumberFormatInfo nfi = NumberFormatInfo.CurrentInfo;


// Define the regular expression pattern.
string pattern;
pattern = @"^\s*[";
// Get the positive and negative sign symbols.
pattern += Regex.Escape(nfi.PositiveSign + nfi.NegativeSign) + @"]?\s?";
// Get the currency symbol.
pattern += Regex.Escape(nfi.CurrencySymbol) + @"?\s?";
// Add integral digits to the pattern.
pattern += @"(\d*";
// Add the decimal separator.
pattern += Regex.Escape(nfi.CurrencyDecimalSeparator) + "?";
// Add the fractional digits.
pattern += @"\d{";
// Determine the number of fractional digits in currency values.
pattern += nfi.CurrencyDecimalDigits.ToString() + "}?){1}$";

Regex rgx = new Regex(pattern);


// Define some test strings.
string[] tests = { "-42", "19.99", "0.001", "100 USD",
".34", "0.34", "1,052.21", "$10.62",
"+1.43", "-$0.23" };


// Check each test string against the regular expression.
foreach (string test in tests)
{
if (rgx.IsMatch(test))
Console.WriteLine("{0} is a currency value.", test);
else
Console.WriteLine("{0} is not a currency value.", test);
}
}
}
// The example displays the following output:
// -42 is a currency value.
// 19.99 is a currency value.
// 0.001 is not a currency value.
// 100 USD is not a currency value.
// .34 is a currency value.
// 0.34 is a currency value.
// 1,052.21 is not a currency value.
// $10.62 is a currency value.
// +1.43 is a currency value.
// -$0.23 is a currency value.

سلام ممنون امکانش هست یه توضیح کوتاه در مورد این کد بدید؟؟؟

mehdi0020
سه شنبه 14 اسفند 1397, 15:18 عصر
سلام .جهت این جور search ها از regx استفاده میکنند. در مورد regular expression در #c جستجو کنید
سلام ممنون از راهنماییتون اگه ممکنه یه سوال داشتم
من میخواهم تمام رشته هایی که هم 3 و هم 7 (حداقل یکی)داخلش هست و بقیه رشته هر کاراکتری ممکنه باشه فازسی یا انگلیسی عدد یا .و.... برام نمایش بده
Regex rgx = new Regex(str)
str چی باید ینویسم؟؟؟

alexmcse
پنج شنبه 16 اسفند 1397, 15:20 عصر
سلام ممنون از راهنماییتون اگه ممکنه یه سوال داشتم
من میخواهم تمام رشته هایی که هم 3 و هم 7 (حداقل یکی)داخلش هست و بقیه رشته هر کاراکتری ممکنه باشه فازسی یا انگلیسی عدد یا .و.... برام نمایش بده
Regex rgx = new Regex(str)
str چی باید ینویسم؟؟؟

private readonly List<int> listAll = new List<int>() {1, 2, 3, 35, 47,87, 335}; private void button3_Click(object sender, EventArgs e)
{
var s = "";


foreach (var VARIABLE in listAll )
{
if (VARIABLE.ToString().StartsWith("3"))
s = s + VARIABLE + Environment.NewLine;
}
MessageBox.Show(s);
//StartsWith
//استفاده کنید
}