本文整理汇总了C#中System.String.Take方法的典型用法代码示例。如果您正苦于以下问题:C# String.Take方法的具体用法?C# String.Take怎么用?C# String.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.Take方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Config
public Config(String[] args)
{
if (args.Count() == 1 && args[0] == "/?")
{
Banners.About();
throw new ConfigurationErrorsException(String.Empty);
}
else
{
if (args.LastOrDefault() == "/verbose")
{
IsVerbose = true;
args = args.Take(args.Count() - 1).ToArray();
}
if (args.Count() != 3)
{
throw new ConfigurationErrorsException("Expected three arguments as explained below.");
}
else
{
ProjectFile = Path.GetFullPath(args[0]);
if (IsVerbose) Console.WriteLine("Resolved %ProjectFile as {0}.", ProjectFile.ToTrace());
if (!File.Exists(ProjectFile))
{
throw new ConfigurationErrorsException(String.Format(
"%ProjectFile (specified as \"{0}\") does not exist.", ProjectFile.ToTrace()));
}
ProjectDir = Path.GetDirectoryName(ProjectFile);
if (IsVerbose) Console.WriteLine("Resolved %ProjectDir as {0}.", ProjectDir.ToTrace());
TemplateFile = Path.GetFullPath(args[1]);
if (IsVerbose) Console.WriteLine("Resolved %TemplateFile as {0}.", TemplateFile.ToTrace());
if (!File.Exists(TemplateFile))
{
throw new ConfigurationErrorsException(String.Format(
"%TemplateFile (specified as \"{0}\") does not exist.", TemplateFile.ToTrace()));
}
DestinationFile = Path.GetFullPath(args[2]);
if (IsVerbose) Console.WriteLine("Resolved %DestinationFile as {0}.", DestinationFile.ToTrace());
if (!File.Exists(DestinationFile))
{
if (IsVerbose) Console.WriteLine("Destination file doesn't exist at {0}. Creating it...", DestinationFile.ToTrace());
var destinationDir = Path.GetDirectoryName(DestinationFile);
if (!Directory.Exists(destinationDir))
{
if (IsVerbose) Console.WriteLine("Destination file directory doesn't exist at {0}. Creating it...", destinationDir.ToTrace());
Directory.CreateDirectory(destinationDir);
if (IsVerbose) Console.WriteLine("Destination file directory successfully created at {0}.", destinationDir.ToTrace());
}
File.WriteAllText(DestinationFile, String.Empty);
if (IsVerbose) Console.WriteLine("Destination file successfully created at {0}.", DestinationFile.ToTrace());
}
}
}
}
示例2: Index
//Search action for games
public ActionResult Index(String search = "")
{
ViewBag.SearchError = search.Length > 50 ? "Search is limited to 50 characters" : "";
search = String.Join("", search.Take(50));
ViewBag.PreviewSearch = search;
var games = db.Games.Where(x => x.Title.Contains(search)).Include(g => g.GameReviews);
return View(games.ToList());
}
开发者ID:CSUSM-Chad-Davies-and-Chris-Lucian,项目名称:AdvancedDatabasesTermProject,代码行数:10,代码来源:GamesController.cs
示例3: Index
//Allows searching of gamers
public ActionResult Index(String search = "")
{
ViewBag.SearchError = search.Length > 50 ? "Search is limited to 50 characters" : "";
search = String.Join("", search.Take(50));
ViewBag.PreviewSearch = search;
//Generates the select statement for the search
//See authors for an example
var gamers = db.Gamers.Where(x => x.Name.Contains(search));
return View(gamers.ToList());
}
开发者ID:CSUSM-Chad-Davies-and-Chris-Lucian,项目名称:AdvancedDatabasesTermProject,代码行数:12,代码来源:GamersController.cs
示例4: PrincipalExtensions_Unit_IsInAllRoles_RolesContainsAllNecessaryRoles
public void PrincipalExtensions_Unit_IsInAllRoles_RolesContainsAllNecessaryRoles()
{
String name = "Chad.Greer";
IIdentity identity = new GenericIdentity(name);
String[] principalRoles = new String[] { "Admin", "Contributor", "Member" };
IPrincipal principal = new GenericPrincipal(identity, principalRoles);
String[] roles = principalRoles.Take(2).ToArray();
Boolean actual = PrincipalExtensions.IsInAllRoles(principal, roles);
Assert.AreEqual(true, actual);
}
示例5: Index
//Search index for Game Reviews
//Also the first page the users see when they connect to the site for the first time
public ActionResult Index(String search = "")
{
ViewBag.SearchError = search.Length > 50 ? "Search is limited to 50 characters" : "";
search = String.Join("", search.Take(50));
ViewBag.PreviewSearch = search;
//Generates the search sql
//See Authors Action for example
var gamereviews = db.GameReviews.Where(x => x.Title.Contains(search)).Include(g => g.Author).Include(g => g.Game);
return View(gamereviews.ToList());
}
开发者ID:CSUSM-Chad-Davies-and-Chris-Lucian,项目名称:AdvancedDatabasesTermProject,代码行数:14,代码来源:GameReviewsController.cs
示例6: ParseLogger
public void ParseLogger(String[] loggerParts, Int32 level)
{
if (level == LoggerLevel)
{
LoggerCount++;
return;
}
//do I have a child logger for this name?
String name = loggerParts.Take(level + 1).Aggregate((s1, s2) => s1 + "." + s2);
var cvm = Childs.SingleOrDefault(vm => vm.LoggerPrefix.Equals(name));
if (cvm == null)
{
cvm = new LoggerViewModel(name);
Childs.Add(cvm);
}
cvm.ParseLogger(loggerParts, level + 1);
}
示例7: Index
//Shows the Authors search page
public ActionResult Index(String search = "")
{
ViewBag.SearchError = search.Length > 50 ? "Search is limited to 50 characters" : "";
search = String.Join("", search.Take(50));
ViewBag.PreviewSearch = search;
//Select statement to the database
//Automatically Generates code into query:
var authors = db.Authors.Where(x => x.Name.Contains(search));
//{SELECT
//[Extent1].[AuthorId] AS [AuthorId],
//[Extent1].[Name] AS [Name],
//[Extent1].[Genre] AS [Genre],
//[Extent1].[Biography] AS [Biography]
//FROM [dbo].[Author] AS [Extent1]
//WHERE [Extent1].[Name] LIKE @p__linq__0 ESCAPE N'~'}
//Views route automatically to views of the same name
return View(authors.ToList());
}
开发者ID:CSUSM-Chad-Davies-and-Chris-Lucian,项目名称:AdvancedDatabasesTermProject,代码行数:22,代码来源:AuthorsController.cs
示例8: Parse
//.........这里部分代码省略.........
continue;
}
if (commands[i].ToUpper() == "THEN")
{
if (innerIfCount != innerThenCount)
{
innerThenCount++;
}
else
{
conditionStart = 0;
conditionEnd = i;
ret = i + 1;
break;
}
}
}
innerIfCount = 0;
int innerElseCount = 0;
for (int i = ret; i < commands.Length; i++)
{
if (commands[i].ToUpper() == "IF")
{
innerIfCount++;
continue;
}
if (commands[i].ToUpper() == "ELSE")
{
if (innerIfCount != innerElseCount)
{
innerElseCount++;
}
else
{
ifStart = ret;
ifEnd = i;
ret = i + 1;
elseDetected = true;
break;
}
}
}
innerIfCount = 0;
int innerEndIfCount = 0;
for (int i = ret; i < commands.Length; i++)
{
if (commands[i].ToUpper() == "IF")
{
innerIfCount++;
continue;
}
if (commands[i].ToUpper() == "ENDIF")
{
if (innerIfCount != innerEndIfCount)
{
innerEndIfCount++;
}
else
{
if (elseDetected)
{
elseStart = ret;
elseEnd = i;
}
else
{
ifStart = ret;
ifEnd = i;
}
ret = i + 1;
break;
}
}
else if (i == commands.Length - 1)
{
if (elseDetected)
{
elseStart = ret;
elseEnd = i + 1;
}
else
{
ifStart = ret;
ifEnd = i + 1;
}
ret = i + 1;
break;
}
}
Condition = commands.Take(conditionEnd).Skip(conditionStart).ToArray();
IfCommands = commands.Take(ifEnd).Skip(ifStart).ToArray();
ElseCommands = commands.Take(elseEnd).Skip(elseStart).ToArray();
return ret;
}
示例9: FormatGuid
protected String FormatGuid(String guid) {
return String.Format("{0}..{1}", new String(guid.Take(5).ToArray()), new String(guid.Skip(Math.Max(0, guid.Count() - 3)).Take(3).ToArray()));
}