本文整理汇总了C#中System.String.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# String.CompareTo方法的具体用法?C# String.CompareTo怎么用?C# String.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.CompareTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: start
/// <summary>
/// Attempts to start the selected process. - BC
/// </summary>
/// <returns>Return value of the attempted command.</returns>
public static int start(String program)
{
//MRM Get a list of all programs installed and basic information about them from Windows
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Product");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection collection = searcher.Get();
//MRM The closest filename and the full path to the file
String full = null;
String closest = null;
//MRM Loop through all the programs installed
foreach (ManagementObject mObject in collection)
{
//MRM See if this is the correct program to be looking at
if (((String)mObject["name"]).ToLower() == program.ToLower() && (String)mObject["InstallLocation"] != null)
{
//MRM Get the install location for the application since it is the one we are looking for
String[] fileNames = System.IO.Directory.GetFiles((String)mObject["InstallLocation"]);
foreach (String fileName in fileNames)
{
//MRM Grab the actual filename to check
String[] fileSplit = fileName.Split('\\');
String file = fileSplit[fileSplit.Length - 1];
//MRM Make sure the file is executable and is not meant for updating or installing the application
if (file.Contains(".exe") && file.Substring(file.Length-4) == ".exe" && (!file.ToLower().Contains("update") && !file.ToLower().Contains("install")))
{
//MRM Replace all underscored with spaces to make it more towards the normal file naming convention
file = file.Replace("_", " ");
//MRM Get the first part of the file before any extension of . due to standard naming conventions
String[] fileNonTypes = file.Split('.');
file = fileNonTypes[0];
//MRM If there is no guess assume we are correct for now
if (closest == null)
{
full = fileName;
closest = file;
}
//MRM Else if the current file is closer than our previous guess, select that file
else if (Math.Abs(program.CompareTo(closest)) >= Math.Abs(program.CompareTo(file)))
{
full = fileName;
closest = file;
}
}
}
break;
}
}
//MRM If we have found an adequte file to launch, launch the file.
if (full != null)
{
//MRM Start a process with the correct information
Process p = new Process();
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.RedirectStandardInput = false;
p.StartInfo.FileName = full;
p.Start();
return 1;
}
return -1;
}
示例2: SearchByName
public int SearchByName(List<Fund> Fundlist, String name)
{
//建议在抓取之后就按基金名称排序
List<Fund> fundlist = new List<Fund>(Fundlist.ToArray());
//按基金名称排序
fundlist.Sort(compar);
int start = 0;
int end = fundlist.Count - 1;
int mid = 0;
//折半查找
while (start <= end)
{
mid = (start + end) / 2;
Console.WriteLine(mid + " " + start + " " + end);
if (fundlist[mid].Name.Equals(name))
break;
else if (name.CompareTo(fundlist[mid].Name) < 0)
end = mid - 1;
else if (name.CompareTo(fundlist[mid].Name) > 0)
start = mid + 1;
}
//原先的Fundlist该基金的位置
int i = SearchByCode(Fundlist, fundlist[mid].Code);
return i;
}
示例3: setRelayState
public void setRelayState(String rState) {
if(rState.CompareTo("on")==0) {
relayState = true;
computeLogic();
} else if(rState.CompareTo("off") == 0) {
relayState = false;
computeLogic();
}
}
示例4: input
/// <summary>
/// A method sending an event, which is here simply the argument + 1.
/// Note that there is no return type to the method, because we use events to send
/// information in WComp. Return values don't have to be used.
/// </summary>
public void input(String str) {
if(str.CompareTo("True") == 0) {
FireStringEvent("on");
} else if(str.CompareTo("False") == 0) {
FireStringEvent("off");
} else {
double d = Double.Parse(str);
FireIntEvent((int)d);
FireDoubleEvent(d);
}
}
示例5: GetResourceImage
/// <summary>
/// get an image from resources (image resources are located in [current_dir]\Drawables and all have .png extension)
/// </summary>
/// <param name="imageName">image name without extension</param>
/// <returns></returns>
public static Image GetResourceImage(String imageName)
{
if (imageName.CompareTo("menu") == 0) imageName = "main";
if (imageName.CompareTo("minimal") == 0) imageName = "scroll";
Image image = new Image();
System.IO.FileInfo fileInfo = new System.IO.FileInfo(Directory.GetCurrentDirectory() + "\\Drawables\\" + imageName + ".png");
BitmapImage src = new BitmapImage();
src.BeginInit();
src.CacheOption = BitmapCacheOption.OnLoad;
src.UriSource = new Uri(fileInfo.FullName, UriKind.Relative);
src.EndInit();
image.Source = src;
return image;
}
示例6: IsFutureCode
public Boolean IsFutureCode(String code)
{
if (code.CompareTo(this.KtbFuture_3yr_1.Code) == 0 ||
code.CompareTo(this.KtbFuture_10yr_1.Code) == 0)
{
return true;
}
if (UnittestCodes.ContainsKey(code))
{
return true;
}
return false;
}
示例7: AddLock
public static void AddLock(String name)
{
lock (_masterLock)
{
if (Locks.ContainsKey(name))
{
throw new Exception(String.Format("Specified lock with name {0} already exists", name));
}
else
{
for (int i = 0; i < Keys.Count; i++)
{
if (name.CompareTo(Keys[i]) < 0)
{
lock (Locks[Keys[i]])
{
Keys.Insert(i, name);
}
break;
}
}
if (!Keys.Contains(name))
{
Keys.Add(name);
}
Locks.Add(name, new object());
}
}
}
示例8: ChangeState
/// <summary>
/// A method sending an event, which is here simply the argument + 1.
/// Note that there is no return type to the method, because we use events to send
/// information in WComp. Return values don't have to be used.
/// </summary>
public void ChangeState(String stateStr) {
if(stateStr.CompareTo("on")==0) {
try{
RPi.I2C.Net.I2CBus.instance.WriteBytes(0x12, new byte[] {0x00,0x01});
FireStringEvent("on");
}catch{}
}
if(stateStr.CompareTo("off")==0) {
try{
RPi.I2C.Net.I2CBus.instance.WriteBytes(0x12, new byte[] {0x00,0x00});
FireStringEvent("off");
}catch{}
}
}
示例9: artistCompare
static Int32 artistCompare(String x, String y)
{
x = (x.ToLower().StartsWith("the ") ? x.ToLower().Replace("the ", "") : x);
y = (y.ToLower().StartsWith("the ") ? y.ToLower().Replace("the ", "") : y);
return x.CompareTo(y);
}
示例10: Debug
/// <summary>
/// Constructor
/// </summary>
/// <param name="fileName">Path and file name of log</param>
/// <param name="debInf">Debug informations includng level, verbose, rotation information</param>
public Debug(String fileName, ref DebugInformations debInf)
{
if (fileName.CompareTo("") == 0)
{
fileName = this._FileName;
}
Regex re = new Regex(@"\w+:\\\w+", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
if (re.IsMatch(fileName))
{
this._Path = fileName.Substring(0, fileName.LastIndexOf('\\'));
if (System.IO.Directory.Exists(this._Path))
{
this._FileName = fileName;
}
else
{
String exepath = Environment.GetCommandLineArgs()[0];
this._Path = exepath.Substring(0, exepath.LastIndexOf('\\'));
this._FileName = this._Path + "\\" + fileName;
}
}
else
{
String exepath = Environment.GetCommandLineArgs()[0];
this._Path = exepath.Substring(0, exepath.LastIndexOf('\\'));
this._FileName = this._Path + "\\" + fileName;
}
this._DebugInfo = debInf;
this._DebugInfo.Level = 1;
}
示例11: IsKtbCode
public Boolean IsKtbCode(String code)
{
if (code.CompareTo(KtbSpot__3yr.Code) == 0||
code.CompareTo(KtbSpot_5yr.Code) == 0||
code.CompareTo(KtbSpot_10yr.Code) == 0)
{
return true;
}
if (this.UnittestCodes.ContainsKey(code))
{
return true;
}
return false;
}
示例12: IsEmpty
public static Boolean IsEmpty(String input)
{
if (input.CompareTo("empty") == 0)
{
return true;
}
return false;
}
示例13: SearchByCode
//两个函数返回的都是基金的在列表中的index
public int SearchByCode(List<Fund> Fundlist,String code)
{
int start = 0;
int end = Fundlist.Count - 1;
int mid = 0;
//折半查找
while(start <= end){
mid = (start + end)/2;
Console.WriteLine(mid + " " + start + " " + end);
if(Fundlist[mid].Code.Equals(code))
return mid;
else if(code.CompareTo(Fundlist[mid].Code) < 0)
end = mid - 1;
else if(code.CompareTo(Fundlist[mid].Code) > 0)
start = mid + 1;
}
return -2;
}
示例14: UpdateUI
public override void UpdateUI(String strategyName, String header, String jsonData)
{
if (header.CompareTo(StrategyCommand.WAS_DIFF_DATA) == 0)
{
Serializer ser = new Serializer(typeof(Was_Diff_DataForUI));
Was_Diff_DataForUI data = (Was_Diff_DataForUI)ser.Deserialize(jsonData);
DrawDiffData(data);
}
}
示例15: OnCompare
/// <summary>
/// Date compare
/// </summary>
protected override Int32 OnCompare(String lhs, String rhs)
{
try
{
return DateTime.Parse(lhs).CompareTo(DateTime.Parse(rhs));
}
catch
{
return lhs.CompareTo(rhs);
}
}