本文整理汇总了C#中System.Uri.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.Substring方法的具体用法?C# Uri.Substring怎么用?C# Uri.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.Substring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Console.WriteLine("ymir2xml converter by xenor");
Console.WriteLine("Copyright (c) 2012 - All Rights reserved.");
Console.WriteLine("-----------------------------------------");
args = new string[] { "group.txt" };
if (args.Length == 0)
{
Console.WriteLine("Drag and drop files to the executable to begin.");
}
else
{
foreach (string filename in args)
{
string relFilename = filename;
try
{
relFilename = new Uri(System.IO.Directory.GetCurrentDirectory() + @"\").MakeRelativeUri(new Uri(filename)).ToString();
}
catch { }
if (relFilename.Substring(relFilename.Length - 3, 3) == "xml")
{
Console.WriteLine("parse xml file");
parseXML(filename);
}
else if ((relFilename.Length >= 4 && relFilename.Substring(0, 4) == "boss") || (relFilename.Length >= 3 && relFilename.Substring(0, 3) == "npc") || (relFilename.Length >= 5 && relFilename.Substring(0, 5) == "regen") || (relFilename.Length >= 5 && relFilename.Substring(0, 5) == "stone"))
{
Console.WriteLine("parse regen file");
parseRegenfile(filename);
}
else if (relFilename.Length >= 11 && relFilename.Substring(0, 11) == "group_group")
{
Console.WriteLine("parse group_group file");
parseGroupGroupfile(filename);
}
else if (relFilename.Length >= 5 && relFilename.Substring(0, 5) == "group")
{
Console.WriteLine("parse group file");
parseGroupfile(filename);
}
else if (relFilename.Length >= 7 && (relFilename.Substring(0, 7) == "Setting" || relFilename.Substring(0, 7) == "setting"))
{
Console.WriteLine("parse settings file");
parseSetting(filename);
}
else
{
Console.WriteLine(relFilename + " - Unknown filetype");
}
}
}
Console.WriteLine("done");
Console.ReadKey();
}
示例2: GetMediaId
/// <summary>
/// 取得媒體ID
/// </summary>
/// <param name="Url">網址</param>
/// <returns>媒體ID</returns>
private string GetMediaId(string Url) {
string result = new Uri(Url).Segments.Last<string>();
try {
result = result.Substring(0, result.IndexOf("_"));
} catch { }
return result;
}
示例3: MakeURLPretty
private string MakeURLPretty(string url)
{
var lowURL = url.ToLower();
if (lowURL.StartsWith("http://www"))
{
// Everything's good.
}
else if (lowURL.StartsWith("http://"))
{
var s = url.Split(new string[] { "//" }, StringSplitOptions.None);
url = s[0] + "//www." + s[1];
}
else if (lowURL.StartsWith("www"))
{
url = "http://" + url;
}
else
{
url = "http://www." + url;
}
url = new Uri(url).ToString();
if (url.EndsWith("/"))
{
url = url.Substring(0, url.Length - 1);
}
return url;
}
示例4: Main
static void Main(string[] args)
{
CTHReader cth = new CTHReader();
if (ConfigurationManager.AppSettings["passwordPrompt"] == "true")
{
Console.WriteLine("Please provide user name to connect to the site:");
cth.UserName = Console.ReadLine();
Console.WriteLine("Please provide the password:");
cth.UserPassword = getPassword();
Console.WriteLine();
}
cth.OutputFilePrefix = ConfigurationManager.AppSettings["outputFilePrefix"];
string outputLocation = ConfigurationManager.AppSettings["outputLocation"];
string siteUrl = new Uri(ConfigurationManager.AppSettings["siteUrl"]).ToString();
if (siteUrl.EndsWith("/"))
{
siteUrl = siteUrl.Substring(0, siteUrl.Length - 1);
}
Console.WriteLine(cth.ProcessCTH(siteUrl, outputLocation, CTHReader.CTHQueryMode.CTHAndSiteColumns));
//doit();
//tidyUpXMLDoc();
//queryXMLProcess();
}
示例5: AbsolutoParaRelativo
public static string AbsolutoParaRelativo(string de, string para, string inicio)
{
string path = new Uri(para).MakeRelativeUri(new Uri(de)).ToString();
path = path.Substring(path.LastIndexOf(inicio), path.Length - path.LastIndexOf(inicio));
return "~" + path;
}
示例6: GetLayoutHtml
public static string GetLayoutHtml(CommonViewModel model, string page, IEnumerable<string> stylesheets, IEnumerable<string> scripts)
{
if (model == null) throw new ArgumentNullException("model");
if (page == null) throw new ArgumentNullException("page");
if (stylesheets == null) throw new ArgumentNullException("stylesheets");
if (scripts == null) throw new ArgumentNullException("scripts");
var applicationPath = new Uri(model.SiteUrl).AbsolutePath;
if (applicationPath.EndsWith("/")) applicationPath = applicationPath.Substring(0, applicationPath.Length - 1);
var pageUrl = "assets/app." + page + ".html";
var json = Newtonsoft.Json.JsonConvert.SerializeObject(model, Newtonsoft.Json.Formatting.None, new Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() });
var additionalStylesheets = BuildTags("<link href='{0}' rel='stylesheet'>", applicationPath, stylesheets);
var additionalScripts = BuildTags("<script src='{0}'></script>", applicationPath, scripts);
return LoadResourceString("Thinktecture.IdentityServer.Core.Views.Embedded.Assets.app.layout.html",
new
{
siteName = model.SiteName,
applicationPath,
pageUrl,
model = json,
stylesheets = additionalStylesheets,
scripts = additionalScripts
});
}
示例7: CreateImageFolder
public static void CreateImageFolder(this string itemName)
{
var path = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
var mainPath = path.Substring(0, path.IndexOf("bin", 0));
var imgPath = string.Format(@"{0}\Content\images\item\{1}", mainPath, itemName);
if (!Directory.Exists(imgPath))
Directory.CreateDirectory(imgPath);
}
示例8: BuildHost
private string BuildHost(string website)
{
var host = new Uri(website, UriKind.Absolute).Host;
if (host.Contains("www."))
{
host = host.Substring(4);
}
return host;
}
示例9: PathFromUri
private static string PathFromUri(string uri)
{
string baseUri = new Uri(uri).PathAndQuery;
if (baseUri.StartsWith("/"))
{
baseUri = baseUri.Substring(1);
}
return baseUri;
}
示例10: GetDomain
private static string GetDomain(IConfiguration settings)
{
var domain = new Uri(settings.GetSiteRoot(false)).DnsSafeHost;
if (domain.IndexOf(':') >= 0)
{
domain = domain.Substring(0, domain.IndexOf(':'));
}
return domain;
}
示例11: Compiler
public Compiler()
{
configFileName = "config.cpp";
stdLibPath = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath;
stdLibPath = stdLibPath.Substring(0, stdLibPath.LastIndexOf('\\')) + "\\stdLibrary\\";
addFunctionsClass = true;
outputFolderCleanup = true;
printOutMode = 0;
flagDefines = new List<PPDefine>();
SqfCall.readSupportInfoList();
includedFiles = new List<string>();
}
示例12: TransformRobocode
public static void TransformRobocode()
{
var w = new Uri("http://robocode.sourceforge.net/docs/robocode/allclasses-noframe.html").ToWebString();
var zip = new ZIPFile();
var o = 0;
while (o >= 0)
{
const string pregfix = "<A HREF=\"";
var i = w.IndexOf(pregfix, o);
if (i >= 0)
{
var j = w.IndexOf("\"", i + pregfix.Length);
if (j >= 0)
{
var type = w.Substring(i + pregfix.Length, j - (i + pregfix.Length));
const string suffix = ".html";
if (type.EndsWith(suffix))
{
o = j + 1;
type = type.Substring(0, type.Length - suffix.Length).Replace("/", ".");
Console.WriteLine(type);
zip.Add(type.Replace(".", "/") + ".cs",
new DefinitionProvider(
type
// "robocode.BattleRules"
// //"java.net.InetSocketAddress"
// //"java.net.ServerSocket"
// //"java.nio.channels.ServerSocketChannel"
, k => k.ToWebString()).GetString()
);
}
else o = -1;
}
else o = -1;
}
else o = -1;
}
using (var ww = new BinaryWriter(File.OpenWrite("Robocode.zip")))
{
zip.WriteTo(ww);
}
}
示例13: BeforeRequest
public bool BeforeRequest(Session session, Rule rule)
{
Console.WriteLine(String.Format("Request ({0}) cached due to the rule: {1}", session.hostname, rule.Name));
// TODO:
// Cache-Control - Expires, MaxAge (private)
// Age?
//
var querystring = new Uri(session.fullUrl).Query;
var startindex = querystring.IndexOf("&url=");
var length = querystring.IndexOf("&ei", startindex) - startindex;
var url = querystring.Substring(startindex, length);
session.fullUrl = Uri.UnescapeDataString(url);
return false;
}
示例14: FindPath
private bool FindPath(string rawUrl, out string foundUri)
{
foundUri = new Uri(rawUrl, UriKind.Relative).NormalizedPathAndQuery();
if (_contentState.Storage.ContainsKey(foundUri))
return true;
int pos;
char[] args = new char[] {'?', '&'};
while((pos = foundUri.LastIndexOfAny(args)) > 0) //not possible to find index zero, i.e. '/?'
{
foundUri = foundUri.Substring(0, pos);
if (_contentState.Storage.ContainsKey(foundUri))
return true;
}
return false;
}
示例15: LoadPlaylist
public override void LoadPlaylist(string fpath)
{
ItemsPaths = new ArrayList();
//
try
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.XmlResolver = null;
settings.DtdProcessing = DtdProcessing.Ignore;
settings.ValidationType = ValidationType.None;
using (XmlReader reader = XmlReader.Create(fpath, settings))
{
CheckFileType(reader);
while (reader.ReadToFollowing("key"))
{
reader.ReadStartElement("key");
if (reader.ReadString().ToLower().Equals("location"))
{
reader.ReadEndElement();
reader.ReadStartElement("string");
string str = new Uri(reader.ReadString().Trim()).LocalPath;
if (str.StartsWith(@"\\localhost\")) str = str.Substring(12);
ItemsPaths.Add(str);
reader.ReadEndElement();
}
else
reader.ReadEndElement();
}
}
}
catch (IOException)
{
throw new Exception("Error occured during the file reading process!");
}
catch (XmlException)
{
throw new Exception("Error occured during the file parsing process!");
}
}