本文整理匯總了C#中System.String.Select方法的典型用法代碼示例。如果您正苦於以下問題:C# String.Select方法的具體用法?C# String.Select怎麽用?C# String.Select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.String
的用法示例。
在下文中一共展示了String.Select方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: IsChaveAcessoValida
/// <summary>
/// Valida a Chave de Acesso de um documento fiscal.
/// </summary>
/// <param name="chaveAcesso">Chave de Acesso</param>
/// <returns>verdadeiro caso a Chave de Acesso seja valida, false caso contrário.</returns>
public static Boolean IsChaveAcessoValida(String chaveAcesso)
{
if (String.IsNullOrWhiteSpace(chaveAcesso) || chaveAcesso.Length != 44)
{
return false;
}
if (!Regex.IsMatch(chaveAcesso, @"^\d{44}$"))
{
return false;
}
int[] digitos = chaveAcesso.Select(x => int.Parse(x.ToString())).ToArray();
int soma = 0, dv, m;
for (int i = digitos.Length - 2; i >= 0; )
{
for (int p = 2; p <= 9 && i >= 0; p++, i--)
{
soma += digitos[i] * p;
}
}
m = (soma % 11);
dv = m <= 1 ? 0 : dv = 11 - m;
return dv == digitos.Last();
}
示例2: SelectProperty
public void SelectProperty(string name, Button openPopupWithThis)
{
var parentWindow = Web.PortalDriver.Title;
Wait.Until(d => openPopupWithThis.Exists);
openPopupWithThis.AsyncClick();
Thread.Sleep(2000);
PopUpWindow.SwitchTo(Title);
// Switch to the frame within this popup dialog
Web.PortalDriver.SwitchTo()
.Frame(Web.PortalDriver.FindElement(By.Id("ifrmAttributeTable")));
Wait.Until(d => new Container(By.Id("spanAttributeName")).Exists);
var parsedName = name.Split('.');
var path = new String[parsedName.Length - 1];
Array.Copy(parsedName, path, parsedName.Length - 1);
var propertyName = parsedName.Last();
foreach (var expander in path.Select(attr => new Button(By.XPath(String.Format("//*[@id='spanAttributeName' and text()='{0}']/../../td[1]/a", attr))))) {
expander.Click();
}
var property = new Container(By.XPath(String.Format("//*[@id='spanAttributeName' and text()='{0}']", propertyName)));
property.Click();
// Switch back out of frame
PopUpWindow.SwitchTo(Title);
OkButton.Click();
PopUpWindow.SwitchTo(parentWindow);
}
示例3: Matches
public bool Matches(String str)
{
var chars = str.Distinct().Select(x => x.ToString()).ToList();
Dictionary<string, Boolean> mapping = new Dictionary<string, bool>();
mapping.Add(chars[0], true);
mapping.Add(chars[1], false);
var match = str.Select(x => mapping[x.ToString()]).Zip(BooleanPattern, (x, y) => x == y).All(x => x==true);
if (match)
return true;
mapping.Clear();
mapping.Add(chars[0], false);
mapping.Add(chars[1], true);
match = str.Select(x => mapping[x.ToString()]).Zip(BooleanPattern, (x, y) => x == y).All(x => x == true);
return match;
}
示例4: GetQualifiedValues
public JsonResult GetQualifiedValues(String part, String locale, String[] keys)
{
if (!_context.DebugMode)
throw new Exception("Unauthorized: DebugMode not on.");
var values = keys == null
? Enumerable.Empty<FlattenedQualifiedValue>()
: keys.Select(key => new FlattenedQualifiedValue(_context.Repository.GetQualified(new Qualifier.Unique(Part.Parse(part), new Locale(locale), key))));
return Json(new { Success = true, Values = values }, JsonRequestBehavior.AllowGet);
}
示例5: TransformSpecialCase
internal static string TransformSpecialCase(IRow theRow, short redLightDiviser, short numberOfLightsOn)
{
var lightsOn = new String('\0', numberOfLightsOn);
lightsOn = String.Join("", lightsOn.Select((light, index) =>
CheckIfIsTimeToUseRed(index, redLightDiviser)
? BerlinClockConstants.RedLight : BerlinClockConstants.YellowLight));
return AppendLightsOffAndLineBreak(theRow.NumberOfLights, lightsOn, theRow.HasLineBreak);
}
示例6: ComputeCrcHash
public uint ComputeCrcHash(String input)
{
Byte[] bytes = input.Select(c => (byte) c).ToArray();
uint crc = bytes.Aggregate(0xffffffff, (current, b) => (current >> 8) ^ CrcTable[(current ^ b) & 0xff]);
crc = crc ^ 0xffffffff;
return crc;
}
示例7: reconstructMessage
public static String reconstructMessage(String s, int k)
{
var r = s.GroupBy(x => x)
.Select(x => new KeyValuePair<int, char>(x.Count(), x.First()))
.Aggregate(
new {
pr = new KeyValuePair<int, char>(0, '0'),
alphabet = "abcdefghijklmnopqrstuvwxyz"
},
(seed, x) => {
if (s.Count() - x.Key == k)
return new { pr = x, alphabet = String.Join("", seed.alphabet.Except(new String(x.Value, 1))) };
return new { pr = seed.pr, alphabet = String.Join("", seed.alphabet.Except(new String(x.Value, 1))) };
});
if (r.pr.Key != 0) return String.Join("", s.Select(x => new String(r.pr.Value, 1)));
return String.Join("", s.Select(x => new String(r.alphabet.First(), 1)));;
}
示例8: Main
static void Main(string[] args)
{
while (true)
{
// sleeps 10 milliseconds not to eat out cpu time
Thread.Sleep(10);
String action = Console.ReadLine().Trim();
switch (action)
{
case "ready?":
Console.WriteLine("ready!");
Console.Out.Flush();
break;
case "generate code":
// makes a list of 25 dots, converts one of them in a sharp, splits the string in
// 5 tokens of 5 characters each
List<char> row = new String('.', 25).ToCharArray().ToList();
row[new Random().Next(24)] = '#';
List<string> rows = new List<string>();
for (int i = 0; i < 5; i++)
rows.Add(string.Join("", row.Select(c => c.ToString())
.Skip(i*5)
.Take(5)
.ToArray()));
foreach (string s in rows)
{
Console.WriteLine(s);
Console.Out.Flush();
}
break;
case "find code":
List<string> code = new List<string>();
for (int i = 0; i < 5; i++)
code.Add(Console.ReadLine());
for (int y = 0; y < 5; y++)
{
int x = code[y].IndexOf('#');
if (x != -1)
{
Console.WriteLine("{0} {1}", x, y);
Console.Out.Flush();
}
}
break;
case "bye!":
Console.WriteLine("bye!");
Console.Out.Flush();
System.Environment.Exit(0);
break;
}
}
}
示例9: set_x
static String[] set_x(String[] board, Char c)
{
bool changed = false;
return board
.Select(xs =>
String.Join("", xs.Select(x =>
{
if (changed == false && x == '?')
{
changed = true;
return c;
}
return x;
}))
)
.ToArray();
}
示例10: SelectProperty
public void SelectProperty(string name)
{
// Switch to the frame within this popup dialog
Web.PortalDriver.SwitchTo()
.Frame(Web.PortalDriver.FindElement(By.Id("ifrmAttributeTable")));
Wait.Until(d => new Container(By.Id("spanAttributeName")).Exists);
var parsedName = name.Split('.');
var path = new String[parsedName.Length - 1];
Array.Copy(parsedName, path, parsedName.Length - 1);
//var propertyName = parsedName.Last();
foreach (var expander in path.Select(attr => new Button(By.XPath(String.Format("//*[@id='spanAttributeName' and text()='{0}']/../../td[1]/a", attr))))) {
expander.Click();
}
var property = new Container(By.XPath(String.Format("//*[@id='spanQualifiedAttributeDisplayName' and text()='{0}']/../span", name)));
property.Click();
Web.PortalDriver.SwitchTo().DefaultContent();
}
示例11: _SearchResults
[OutputCache(CacheProfile = "NoCacheProfile")] // TODO: Can't we just vary cache by parameter, when does it crawl ?
public ActionResult _SearchResults(String searchTerm, String[] sources, String[] refiners, Int32 iDisplayLength = 10, Int32 iDisplayStart = 0)
{
Dictionary<String, String> srcs = null;
if (sources != null && sources.Length > 0)
{
srcs = sources.Select(src => src.Split(':')).ToDictionary(defs => defs[0], defs => defs[1]);
}
Dictionary<String, String> refs = null;
if (refiners != null && refiners.Length > 0)
{
var rs = refiners.Select(r => new Tuple<String, String>(r.Split(new Char[] { ':' })[0], r.Split(new Char[] { ':' })[1]))
.GroupBy(r => r.Item1);
refs = rs.ToDictionary(g => g.Key, g => g.Select(t => t.Item2).Aggregate((a, b) => a + "," + b));
}
var searchContent = _businessModule.GetSearchResults(searchTerm, srcs, refs, iDisplayStart, iDisplayLength);
return PartialView(searchContent);
}
示例12: luhnCheck
// Luhn Check methods (http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#C.23)
private static bool luhnCheck(String cardNumber)
{
return luhnCheck(cardNumber.Select(c => c - '0').ToArray());
}
示例13: Map
public void Map(String typeName, String[] queueName)
{
_typeNames.Add(typeName);
_typeNamesMap.Add(typeName, queueName.Select(name => new QueueName(name)).ToArray());
}
示例14: GetPitches
private PitchType[] GetPitches(String pitches)
{
return pitches.Select(p => GetPitchType(p)).ToArray();
}
示例15: Main
/// <summary>
/// Entry point - pass "verbose" as a command-line
/// argument to initialize Embree in verbose mode.
/// </summary>
public static int Main(String[] args)
{
try
{
var verbose = (args.Select(s => s.ToLower()).Contains("verbose"));
if (verbose) args.Select(s => s != "verbose"); // Clean up arglist
ParseCommandLineArguments(args); // For selecting ray packet sizes
if (verbose)
{
Console.WriteLine("Embree.NET Benchmark [VERBOSE]");
Console.WriteLine("==============================");
RTC.Register("verbose=999"); // max verbosity?
}
else
{
Console.WriteLine("Embree.NET Benchmark");
Console.WriteLine("====================");
}
Console.WriteLine(""); // this is for debugging
Console.WriteLine("[+] " + Bits + "-bit mode.");
// Note this is similar to the original Embree benchmark program
Console.WriteLine("[+] Performance indicators are per-thread.");
{
// Benchmark parameters
int w = 1024, h = 1024;
Console.WriteLine("[+] Benchmarking intersection queries.");
foreach (var item in Benchmarks.Intersections(SceneFlags.Static, Flags, 501, w, h))
Measure(item.Item2, item.Item3, (s) => Console.WriteLine(" {0} = {1}", item.Item1.PadRight(35), s));
Console.WriteLine("[+] Benchmarking occlusion queries.");
foreach (var item in Benchmarks.Occlusions(SceneFlags.Static, Flags, 501, w, h))
Measure(item.Item2, item.Item3, (s) => Console.WriteLine(" {0} = {1}", item.Item1.PadRight(35), s));
}
/*{
Console.WriteLine("[+] Benchmarking geometry manipulations.");
foreach (var item in Benchmarks.Geometries(SceneFlags.Static, Flags))
Measure(item.Item2, item.Item3, (s) => Console.WriteLine(" {0} = {1}", item.Item1.PadRight(35), s));
}*/
if (verbose)
RTC.Unregister();
return EXIT_SUCCESS;
}
catch (Exception e)
{
var msg = e is AggregateException ? e.InnerException.Message : e.Message;
Console.WriteLine(String.Format("[!] Error: {0}.", msg));
Console.WriteLine("\n========= STACK TRACE =========\n");
Console.WriteLine(e.StackTrace);
return EXIT_FAILURE;
}
}