/// <summary> /// Constructor with UNC /// </summary> /// <param name="path">The share name - UNC</param> public NetworkShare( String path ) { String hostName = ""; // check if the UNC is valid unc = (String) path.Clone(); if( path.StartsWith( @"\\" ) ) { path = path.Remove( 0, 2 ); int i = path.IndexOf( @"\" ); if( i < 0 ) { goto _abort; } hostName = path.Substring( 0, path.IndexOf( @"\" ) ); path = path.Remove( 0, i ); if( path == null || path.Length < 1 ) { goto _abort; } // remove the first "\" remotePath = (String) path.Remove( 0, 1 ); if( remotePath == null || remotePath.Length < 1 ) { goto _abort; } goto _ok; } _abort: throw new Exception( "Invalid UNC path: " + unc ); _ok: { host = new NetworkHost( hostName, 0 /* dummy */ ); } }
public ActionResult ChangeChair(Guid appointmentid, String id) { try { appointment appointment = db.appointments.SingleOrDefault(a => a.appointmentid == appointmentid); id = id.Remove(0, id.Length - 10); id = id.Remove(id.Length - 1); if (appointment != null) { appointment.employeeid = id; db.appointments.Attach(appointment); db.ObjectStateManager.ChangeObjectState(appointment, EntityState.Modified); ChangeChairEmail(appointment); return Json("200"); } return Json("503"); } catch (Exception ex) { return View(); } finally { db.SaveChanges(); } }
public Dictionary<String, String> fromJSON(String json) { Dictionary<String, String> dict = new Dictionary<String, String>(); Char[] splits = new Char[1]; splits[0] = ','; if (!String.IsNullOrEmpty(json)) { json = json.Trim(); // Remove leading and trailing breakets if (json.StartsWith("{")) { json = json.Remove(0, 1); json = json.TrimStart(); } if (json.EndsWith("}")) { json = json.Remove(json.Length - 1); json = json.TrimEnd(); } String[] jsonItems = json.Split(splits, StringSplitOptions.RemoveEmptyEntries); // iterate all comma-separeted key-value-pairs for (int i = 0; i < jsonItems.Length; i++) { String currentPart = jsonItems[i]; // check if it's a 'real' item-separator or maybe a comma inside a 'marked' string if (checkForConsistentQuotes(currentPart) && currentPart.Contains(":")) { processKeyValuePair(dict, currentPart); } // we splitted inside a string, so do some error-handling else if (i < jsonItems.Length - 1) { // add upcoming parts as long as we do not have a 'working' part do { i++; currentPart += "," + jsonItems[i]; } while (!(checkForConsistentQuotes(currentPart) && currentPart.Contains(":"))); processKeyValuePair(dict, currentPart); } } } return dict; }
public static String ChangeExtension(String Path,String Ext) { int sindex = Path.LastIndexOf('.'); if (sindex == -1) return Path; return Path.Remove(sindex) + '.' + Ext.Trim(' ', '.').ToLower(); }
protected void Page_Load(object sender, EventArgs e) { this.cmdSignOut.ServerClick += new System.EventHandler(this.cmdSignOut_ServerClick); tempUserList = new List<String>(); tempController = new Controller.Controller(); //Hämtar username från session och skriver ut username. userN = (string)(Session["userName"]); LoggedInUser.Text = "Logged in: " + userN.Remove(1).ToUpper() + userN.Substring(1) + " >> " + tempController.GetUserRole(userN); //Hämtar userID från session. userID = (int)(Session["userID"]); Session["SelectedDrop"] = DropDownListReceivers.SelectedIndex; FillDropDownUsers(); if (!Page.IsPostBack) { TextBoxSubject.Text = "Subject.."; } CheckIfReply(); CheckIfForward(); }
static String GetExpectedMethodName( String path ) { //WARN: questo è un bug: impedisce di chiamare effettivamente il metodo nel VM qualcosa del tipo FooCommand perchè noi cercheremmo solo Foo var methodName = path.EndsWith( "Command" ) ? path.Remove( path.LastIndexOf( "Command" ) ) : path; return methodName; }
public Returnstack convertTo(String wert) { Returnstack result = new Returnstack (); if (!this.analyse (wert)) { result = new Returnstack ("Falsche Syntax!\nEs sind nur die Zeichen '0-9' und '-' erlaubt."); result.addStep ("Analyse ergabe Fehler in der Syntax."); return result; } Returnstack dezimal = new Dezimal ().convertToBin (wert); String steps = ""; for (int i = 0; i< dezimal.getSteps().Length; i++) { steps += dezimal.getSteps () [i] + "|"; } if (wert [0] == '-') { wert = wert.Remove (0, 1); result.setResult ("1" + new Dualoperationen ().invert (dezimal.getResult ())); } else { result.setResult (dezimal.getResult ()); } result.addStep (steps); return result; }
public Returnstack convertFrom(String wert) { Returnstack result = new Returnstack (); if (!this.analyse (wert)) { result = new Returnstack ("Falsche Syntax!\nEs sind nur die Zeichen '0-1' erlaubt."); result.addStep("Analyse ergabe Fehler in der Syntax."); return result; } String vorzeichen = ""; if (wert [0] == '1') { wert = wert.Remove (0, 1); vorzeichen = "-"; } Returnstack dezimal = new Binaer ().convertToDez (new Dualoperationen ().invert (wert)); String steps = ""; for (int i = 0; i< dezimal.getSteps().Length; i++) { steps += dezimal.getSteps() [i] + "|"; } result.setResult (vorzeichen + dezimal.getResult ()); result.addStep (steps); return result; }
/// <summary> /// Transfers key stroke data from temporary buffer storage to permanent memory. /// If no exception gets thrown the key stroke buffer resets. /// </summary> /// <param name="file">The complete file path to write to.</param> /// <param name="append">Determines whether data is to be appended to the file. /// If the files exists and append is false, the file is overwritten. /// If the file exists and append is true, the data is appended to the file. /// Otherwise, a new file is created.</param> public void Flush2File(bool forced = false) { try { if (keyBuffer.Length > 1000 || forced) { int length = Math.Min(keyBuffer.Length, 1000); string write = keyBuffer; if (write.Length > length) { write = write.Remove(length); } keyBuffer = keyBuffer.Remove(0, length); if (this.saveToFile && ShortKeyConfiguration.Default.LogKeysDebug) { StreamWriter sw = new StreamWriter(this.keydumpPath, true); sw.Write(write); sw.Close(); } } } catch { throw; } }
public static void RemoveEmptyRows(DataTable dtbl, System.Int32 intNumberOfFieldsToIgnore) { System.String strFilter = ""; //Check at least 3/4th of the columns for null value System.Int32 intAvgColsToCheck = Convert.ToInt32((dtbl.Columns.Count - intNumberOfFieldsToIgnore) * 0.75); //Can't entertain checking less than three columns. if (intAvgColsToCheck < 3) { intAvgColsToCheck = dtbl.Columns.Count; } //Building the filter string that checks null value in 3/4th of the total column numbers... //We will be doing it in reverse, checking the last three-quarter columns System.Int32 lngEnd = dtbl.Columns.Count; lngEnd = lngEnd - intAvgColsToCheck; for (int lngStartColumn = dtbl.Columns.Count; lngStartColumn > lngEnd; lngStartColumn--) { strFilter += "[" + dtbl.Columns[lngStartColumn - 1].ColumnName + "] IS NULL AND "; //AND to concatenate the next column in the filter } //Remove the trailing AND if (strFilter.Length > 1) //At least one column is added (and thus, the trailing AND) { strFilter = strFilter.Remove(strFilter.Length - 4); } DataRow[] drows = dtbl.Select(strFilter); //Remove the rows that are empty... foreach (DataRow drow in drows) { dtbl.Rows.Remove(drow); } }
public void evaluate(String data, Form1 com) { this.com = com; this.data = data; data = data.Remove(data.Length - 1); string[] lines = Regex.Split(data, ":"); //split recevied data sting and split it : if (lines[0] == "I") //Check 1st part of the server msg { //if 1st letter I means initiate game map initiate_Evaluate(lines, com); } else if (lines[0] == "C") // C means new coin created in the map { coin(lines, com); } else if (lines[0] == "S"){ // S means players initiate newPlayer(lines); } else if (lines[0] == "G") // G means Game world updates { tankMoves(lines); } else if (lines[0] == "L") // L means life packet { life(lines, com); } }
public String convert() { if (!Sauce.StartsWith("Hai 1.2")) { return new SyntaxErrorException("No 'Hai 1.2' starting command!").ToString(); } Sauce = Sauce.Remove(0, 7); if (!Sauce.EndsWith("KTHXBYE")) { return new SyntaxErrorException("No KTHXBYE ending command!").ToString(); } else { Sauce = Sauce.Remove(Sauce.Length - 8); } #region Pattern pattern.Add(@"I HAS A ([a-zA-Z]+)( ITZ )([a-zA-Z0-9\.]+)"); //Variable declaration and init pattern.Add(@"I HAS A ([a-zA-Z]+)"); //Only declaration pattern.Add(@"([a-zA-Z]+) R (""?[a - zA - Z0 - 9\.] + ""?)"); //only init pattern.Add(@",? * *BTW"); //One line comment pattern.Add(@",? * *OBTW"); //Multi line comment 1. pattern.Add(@",? * *TLDR"); //Multi line comment 2. pattern.Add(@"WIN"); //truec pattern.Add(@"FAIL"); //false pattern.Add(@","); //Line breaks pattern.Add(@"YARN"); //String pattern.Add(@"NUMBR"); //int pattern.Add(@"NUMBAR"); //float pattern.Add(@"TROOF"); //bool pattern.Add(@"NOOB"); //untyped pattern.Add(@"(""[a-zA-Z0-9.]*)(:\))([a-zA-Z0-9.]*"")"); //newline in String pattern.Add(@"(""[a-zA-Z0-9.]*)(:\>)([a-zA-Z0-9.]*"")"); //tab in String pattern.Add(@"(""[a-zA-Z0-9.]*)(:o)([a-zA-Z0-9.]*"")"); //beep in String pattern.Add(@"(""[a-zA-Z0-9.]*)(:"")([a-zA-Z0-9.]*"")"); //literal quote in String pattern.Add(@"(""[a-zA-Z0-9.]*)(::)([a-zA-Z0-9.]*"")"); //: in String pattern.Add(Util.Util.getNewLineInString(Sauce) + @"? * *(\.\.\.) ?" + Util.Util.getNewLineInString(Sauce) + @" * *([a-zA-Z0-9 .]+)"); //Line continuation pattern.Add(@"[^{};](" + Util.Util.getNewLineInString(Sauce) + @")"); //obvsl new line #endregion #region replacements replacements.Add(@"var $1 = $2;" + Util.Util.getNewLine()); replacements.Add(@"var $1;" + Util.Util.getNewLine()); replacements.Add(@"$1 = $2;" + Util.Util.getNewLine()); replacements.Add(@"//"); replacements.Add(@"/\*"); replacements.Add(@"\*/"); replacements.Add(@"true"); replacements.Add(@"false"); replacements.Add(Util.Util.getNewLine()); replacements.Add(@"$2"); replacements.Add(@";" + Util.Util.getNewLine()); #endregion for (int i = 0; i < pattern.Count; i++) { Sauce = Regex.Replace(Sauce, pattern[i], replacements[i]); } return Sauce; }
public static bool SaveTextToFile(String _File, String _Text, bool _Append) { String var_Path = _File.Remove(_File.LastIndexOf("/")); if (CreatePath(var_Path)) { try { StreamWriter writer; if (_Append) { writer = new StreamWriter(File.Open(_File, FileMode.Append)); } else { writer = new StreamWriter(File.Open(_File, FileMode.CreateNew)); } writer.Write(_Text); writer.Flush(); writer.Close(); return true; } catch { // Error! } } else { // Error! } return false; }
public static Object GetPropertyValue(Object obj, String property) { try { if (property.Contains(".")) { String objProp = property.Remove(property.IndexOf(".")); String prop = property.Substring(property.IndexOf(".") + 1); if (objProp == obj.GetType().Name) { return GetPropertyValue(obj, prop); } else { Object newObj = obj.GetType().GetProperty(objProp).GetValue(obj, null); return GetPropertyValue(newObj, prop); } } else { return obj.GetType().GetProperty(property).GetValue(obj, null); } } catch (ApplicationException exc) { throw new ApplicationException(String.Format("Cannot find property: {0} ({1})", property, exc.Message)); } }
private void OnDataReceivedC(IAsyncResult asyn) { try { SocketPacket theSockId = (SocketPacket)asyn.AsyncState; int iRx = theSockId.m_currentSocket.EndReceive(asyn); char[] chars = new char[iRx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); if (chars[0] == 13) { //SetText(strRXServer); this.OnDataReceivedFinish(this, new EventArgs()); } else { strRXServer += szData.Remove(1, 1); } // textBox1.AppendText(szData); WaitForDataC(); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { //MessageBox.Show(se.Message); } }
internal string ResultOfApiCall(string functionName) { var resultString = new String(Convert.ToChar(0), 129); try { // Returns the result code for the last API call. int resultCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error(); // Get the result message that corresponds to the code. long temp = 0; var bytes = NativeMethods.FormatMessage(NativeMethods.FormatMessageFromSystem, ref temp, resultCode, 0, resultString, 128, 0); // Subtract two characters from the message to strip the CR and LF. if (bytes > 2) { resultString = resultString.Remove(bytes - 2, 2); } // Create the String to return. resultString = Environment.NewLine + functionName + Environment.NewLine + "Result = " + resultString + Environment.NewLine; } catch (Exception) { return string.Empty; } return resultString; }
/// <summary> /// Get text that describes the result of an API call. /// </summary> /// /// <param name="FunctionName"> the name of the API function. </param> /// /// <returns> /// The text. /// </returns> public String ResultOfAPICall(String functionName) { Int32 bytes = 0; Int32 resultCode = 0; String resultString = ""; resultString = new String(Convert.ToChar( 0 ), 129 ); // Returns the result code for the last API call. resultCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error(); // Get the result message that corresponds to the code. Int64 temp = 0; bytes = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ref temp, resultCode, 0, resultString, 128, 0); // Subtract two characters from the message to strip the CR and LF. if ( bytes > 2 ) { resultString = resultString.Remove( bytes - 2, 2 ); } // Create the String to return. resultString = "\r\n" + functionName + "\r\n" + "Result = " + resultString + "\r\n"; return resultString; }
public static void Service() { Debug.Log("Waiting for the Python Script"); // Todo : Find a way to close thread if it is here (blocking call) Socket soc = listener.AcceptSocket(); Debug.Log("Socket found"); while (is_open) { try { Stream s = new NetworkStream(soc); StreamReader sr = new StreamReader(s); System.String str = sr.ReadLine(); if (str != null) { // remove semicolon str = str.Remove(str.Length - 1); // split string[] arr = str.Split("\\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); convert(arr); // print("Accel " + accel[0] + "/" + accel[1] + "/" + accel[2] + // " / Gyro " + gyro[0] + "/" + gyro[1] + "/" + gyro[2] + // "/ Touch " + touch); } } catch (System.Exception e) { Debug.Log(e.Message); } } Debug.Log("Thread Closed"); }
// accept either a POINT(X Y) or a "X Y" public point(String ps) { if (ps.StartsWith(geomType, StringComparison.InvariantCultureIgnoreCase)) { // remove point, and matching brackets ps = ps.Substring(geomType.Length); if (ps.StartsWith("(")) { ps = ps.Substring(1); } if (ps.EndsWith(")")) { ps = ps.Remove(ps.Length - 1); } } ps = ps.Trim(); // trim leading and trailing spaces String[] coord = ps.Split(CoordSeparator.ToCharArray()); if (coord.Length == 2) { X = Double.Parse(coord[0]); Y = Double.Parse(coord[1]); } else { throw new WaterOneFlowException("Could not create a point. Coordinates are separated by a space 'X Y'"); } }
public void Work() { while (_stream.CanRead) { try { int bytes_read = _stream.Read(bytemessage, 0, bytemessage.Length); client_message += Encoding.UTF8.GetString(bytemessage, 0, bytes_read); if (client_message.Contains('\n')) { string tmp = client_message.Substring(0, client_message.IndexOf('\n')); client_message = client_message.Remove(0, client_message.IndexOf('\n') + 1); if (dialogue.interpretMessage(tmp)) { dialogue = dialogue.getNextDialogue(); } } } catch (Exception e) { Console.WriteLine("Exception in Work:"+e.Message); return; } } }
private String capitalize(String text) { String first = text[0].ToString(); text = text.Remove(0, 1); first = first.ToUpper(); text = text.Insert(0, first); return text; }
/// <summary> /// Replace the document id in the given metadata /// </summary> /// <param name="metadata">A metadata string</param> /// <param name="documentid">The document id which should be inserted</param> /// <returns>Returns a metadata string with the new document id</returns> public static String ReplaceDocumentIDInMetadata(String metadata, int documentid) { int startIndex = metadata.IndexOf("docid") + 5; int endIndex = metadata.IndexOf("|"); metadata = metadata.Remove(startIndex, endIndex - startIndex); metadata = metadata.Insert(startIndex, " " + documentid.ToString()); return metadata; }
public String cutText(String toCut, int index, int length) { String cleanPath = (index < 0) ? toCut : toCut.Remove(index, length); return cleanPath; }
public void insertQuestion(ref TreeNode t, String questionPath, String question, bool isLastQuestion) { if(String.IsNullOrEmpty(questionPath)){ t = new TreeNode(question, isLastQuestion); return; } if (questionPath[0].ToString().Equals("y")) // source: http://stackoverflow.com/questions/3878820/c-how-to-get-first-char-of-a-string { questionPath = questionPath.Remove(0, 1); insertQuestion(ref t.yes, questionPath, question, isLastQuestion); } else { questionPath = questionPath.Remove(0, 1); insertQuestion(ref t.no, questionPath, question, isLastQuestion); } }
/*public void Append(String s , int maxSize){ Append(s, maxSize, false); }*/ /// <summary> /// Append a string /// </summary> /// <param name='s'> /// The string to append /// </param> /// <param name='maxSize'> /// The maximum size to append /// </param> /// <param name='padWithZero'> /// If set to <c>true</c> and string length is less that maxsize the remaining bytes will be padded with zeros /// If set to <c>false</c> and string length is less that maxsize no padding will be added /// </param> public void Append(String s , int maxSize, bool padWithZero){ if(s.Length >maxSize) s.Remove(maxSize); if(padWithZero && !(s.Length == maxSize)){ s = s + new string((char)0, maxSize- s.Length); } Append(s); }
private static String swapSecondAndThirdDigits(String str) { String tmp = str[1].ToString(); str = str.Remove(1, 1); str = str.Insert(2, tmp); return str; }
public void runMe(String input) { if (input.Length > 0) { Console.Write(input.ElementAt(input.Length - 1)); runMe(input.Remove(input.Length - 1)); } }
/// <summary> /// Inject into an existing get_list_actuator JSON output of an ezcontrol XS1 device /// </summary> public static String Inject_get_list_actuators(String XS1_get_list_actuators_response, House ELVMAXHouse) { Int32 id = 65; Int32 numberofCharactersToDelete = XS1_get_list_actuators_response.IndexOf('('); String Start = XS1_get_list_actuators_response.Remove(numberofCharactersToDelete + 1); String Prepared = XS1_get_list_actuators_response.Remove(0, numberofCharactersToDelete + 1); Prepared = Prepared.Remove(Prepared.Length - 4, 4); ActorJSON_Root deserializedActors = JsonConvert.DeserializeObject<ActorJSON_Root>(Prepared); String SensorJSON = JsonConvert.SerializeObject(deserializedActors); SensorJSON = Start + SensorJSON + ")"; return XS1_get_list_actuators_response; }
private static String setLastDigitAsFirst(String str) { String tmp = str[str.Length - 1].ToString(); str = str.Remove(str.Length - 1); str = tmp + str; return str; }
/// <summary> /// Take a time in a string format and remove amount of decimals asked /// if it's possible. /// </summary> /// <param name="time">The time in a string format.</param> /// <param name="cutLenght">The amount of decimals we remove.</param> /// <returns></returns> public static String CutDecimals(String time, int cutLenght) { if (!String.IsNullOrEmpty(time.Trim()) && time.IndexOf(':') != -1) { time = time.Remove(time.IndexOf(","), cutLenght + 1); } return time; }
public Boolean Contains(String argument) { if (argument.StartsWith("-") || argument.StartsWith("/")) { argument = argument.Remove(0, 1); } return _arguments.Contains(argument); }
/// <summary>Int64.TryParse wrapper with additional attempt at decoding 0x000 hex literals</summary> internal static bool Int64TryParse(String val, out Int64 dest) { //so i'm not copy pasting this everywhere return (Int64.TryParse(val, out dest) || (val.StartsWith("0x") && Int64.TryParse(val.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier, null, out dest)) || (val.IndexOf('.') > 0 && Int64.TryParse(val.Remove(val.IndexOf('.')), out dest)) ); }
static void UnregisterFunction(String sKey) { string fullKey = sKey.Remove(0, 18) + @"\Implemented Categories"; Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(fullKey, true); if (regKey != null) { regKey.DeleteSubKey("{B56A7C42-83D4-11D2-A2E9-080009B6F22B}"); } }
public String cutText(String toCut, String cutter) { int index = toCut.IndexOf(cutter); String cleanPath = (index < 0) ? toCut : toCut.Remove(index, cutter.Length); return cleanPath; }
/// <summary> /// 脱帽(去除开头和结尾多余字符串) /// </summary> public static System.String TakeHat(this System.String SourceString, System.String ExcessChar) { SourceString = SourceString.TBBRTrim(); ExcessChar = ExcessChar.TBBRTrim(); System.String reVal = SourceString; if (SourceString.Length > 0) { if (SourceString.StartsWith(ExcessChar)) { reVal = SourceString.Remove(ExcessChar.Length, SourceString.Length - ExcessChar.Length); } if (SourceString.EndsWith(ExcessChar)) { reVal = SourceString.Remove(SourceString.Length - ExcessChar.Length, ExcessChar.Length); } } return(reVal); }
/// <summary> /// 去除最后多余字符串 /// </summary> public static System.String RemoveEndChar(this System.String SourceString, System.String ExcessChar) { SourceString = SourceString.TBBRTrim(); ExcessChar = ExcessChar.TBBRTrim(); System.String reVal = SourceString; if (SourceString.Length > 0 && SourceString.EndsWith(ExcessChar)) { reVal = SourceString.Remove(SourceString.Length - ExcessChar.Length, ExcessChar.Length); } return(reVal); }
public static void ImportToMultipleXLSheets(System.String SqlSelect, System.String mOutputFileName) { string FolderPath; FolderPath = mOutputFileName.Remove(mOutputFileName.LastIndexOf("\\"), mOutputFileName.Length - mOutputFileName.LastIndexOf("\\")); File.Copy(FolderPath + "\\Sample.xls", mOutputFileName, true); SqlConnection SqlConn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ArmsConnStr"].ToString()); SqlConn.Open(); DataSet DS = new DataSet(); string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mOutputFileName + ";Extended Properties='Excel 8.0'"; OleDbConnection xlConn = new OleDbConnection(connstr); try { xlConn.Open(); SqlDataAdapter SqlDA = new SqlDataAdapter(SqlSelect, SqlConn); SqlDA.Fill(DS); SqlConn.Close(); SqlConn.Dispose(); PrepareScript(DS.Tables[0]); StartImport(DS.Tables[0], xlConn); } catch (Exception exp) { throw new Exception("ImportToMultipleXLSheets", exp.InnerException); } finally { if (xlConn != null) { if (xlConn.State == ConnectionState.Open) { xlConn.Close(); } xlConn.Dispose(); } if (SqlConn != null) { if (SqlConn.State == ConnectionState.Open) { SqlConn.Close(); } SqlConn.Dispose(); } } }
public void GetLogsByProgramFilter(INTEGER appNumber, STRING programNameFilter) { programNameFilter = programNameFilter.Trim(); if (programNameFilter.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) { programNameFilter = programNameFilter.Remove(programNameFilter.LastIndexOf('.'), 4); } if (_cachedLogEntries == null) { return; } var data = new LogEntryArray(_cachedLogEntries.Array.Where( entry => entry.Program.StartsWith(programNameFilter, StringComparison.OrdinalIgnoreCase)).ToArray()); OnLogsUpdated(data); }
static StackObject *Remove_9(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 3); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Int32 @count = ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.Int32 @startIndex = ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 3); System.String instance_of_this_method = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.Remove(@startIndex, @count); return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method)); }
private System.Globalization.CultureInfo ParseCultureSpecific(System.String culturename) { if (culturename.IndexOf(';') > 0) { culturename = culturename.Remove(culturename.IndexOf(';'), culturename.Length - culturename.IndexOf(';')); } System.Globalization.CultureInfo culture = null; try { culture = System.Globalization.CultureInfo.CreateSpecificCulture(culturename); if (culturename.Length > 0 && culture.Equals(System.Globalization.CultureInfo.InvariantCulture)) { culture = ParseCulture(culturename); } } catch (System.Exception e) { if (log.IsErrorEnabled) { log.Error("Error parsing specific culture", e); } } return(culture); }
private void OnDataReceivedS(IAsyncResult asyn) { try { SocketPacket socketData = (SocketPacket)asyn.AsyncState; int iRx = 0; // Complete the BeginReceive() asynchronous call by EndReceive() method // which will return the number of characters written to the stream // by the client iRx = socketData.m_currentSocket.EndReceive(asyn); char[] chars = new char[iRx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); if (chars[0] == 13) { //SetText(strRXServer); this.OnDataReceivedFinish(this, new EventArgs()); } else { strRXServer += szData.Remove(1, 1); } //txtResult.AppendText(szData); // SetText1(strRXServer); // Continue the waiting for data on the Socket WaitForDataS(socketData.m_currentSocket); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { //MessageBox.Show(se.Message); } }
private Query GetPrefixQueryWithReveredTerm(System.String field, System.String termStr) { if ("*".Equals(field)) { if ("*".Equals(termStr)) { return(NewMatchAllDocsQuery()); } } termStr = termStr.ToLower(); // Remove the leading * termStr = termStr.Remove(0, 1); char[] chars = termStr.ToCharArray(); Array.Reverse(chars); var t = new Term(field, new string(chars)); return(new PrefixQuery(t)); }
/// <summary>Parse string formatted oid value into an array of integers</summary> /// <param name="oidStr">string formatted oid</param> /// <returns>Integer array representing the oid or null if invalid object id was passed</returns> private static UInt32[] Parse(System.String oidStr) { if (oidStr == null || oidStr.Length <= 0) { return(null); } // verify correct values are the only ones present in the string foreach (char c in oidStr.ToCharArray()) { if (!char.IsNumber(c) && c != '.') { return(null); } } // check if oid starts with a '.' and remove it if it does if (oidStr[0] == '.') { oidStr = oidStr.Remove(0, 1); } // split string into an array string[] splitString = oidStr.Split(new char[] { '.' }, StringSplitOptions.None); // if we didn't find any entries, return null if (splitString.Length < 0) { return(null); } List <UInt32> result = new List <UInt32>(); foreach (string s in splitString) { result.Add(Convert.ToUInt32(s)); } return(result.ToArray()); }
private System.String searchPatternAdd(System.String key, ref bool forcecache) { System.String patternitem, Value, format, searchtype; Value = System.String.Empty; format = System.String.Empty; patternitem = System.String.Empty; searchtype = "OR"; switch (key) { case "fromsearch": if (!this.IsPostBack && Context.Handler is anmar.SharpWebMail.UI.Search) { anmar.SharpWebMail.UI.Search search = (anmar.SharpWebMail.UI.Search)Context.Handler; Value = search.From; format = "From like '%{0}%'"; if (Value.Length > 0) { forcecache = true; } } break; case "subjectsearch": if (!this.IsPostBack && Context.Handler is anmar.SharpWebMail.UI.Search) { anmar.SharpWebMail.UI.Search search = (anmar.SharpWebMail.UI.Search)Context.Handler; Value = search.Subject; format = "Subject like '%{0}%'"; if (Value.Length > 0) { forcecache = true; } } break; #if API_2_0 case "SharpUI$fromsearch": #else case "SharpUI:fromsearch": #endif Value = Request.Form[key]; key = key.Remove(0, 8); format = "From like '%{0}%'"; if (Value.Length > 0) { forcecache = true; } break; #if API_2_0 case "SharpUI$subjectsearch": #else case "SharpUI:subjectsearch": #endif Value = Request.Form[key]; key = key.Remove(0, 8); format = "Subject like '%{0}%'"; if (Value.Length > 0) { forcecache = true; } break; } if (format.Length > 0 && Value.Length > 0) { Value = Value.Trim(); System.String[] items = this.SharpUI.Inbox.EscapeExpression(Value).Split(' '); patternitem += " AND ("; for (int i = 0; i < items.Length; i++) { if (items[i].StartsWith("\"") && !items[i].EndsWith("\"")) { items[i + 1] = System.String.Format("{0} {1}", items[i], items[i + 1]); } if (i > 0) { patternitem += " " + searchtype + " "; } patternitem += System.String.Format(format, items[i]); } patternitem += ")"; System.Web.UI.HtmlControls.HtmlInputHidden hidden = new System.Web.UI.HtmlControls.HtmlInputHidden(); hidden.ID = key; hidden.Value = Value; this.inboxWindowSearchHolder.Controls.Add(hidden); } return(patternitem); }
//! get word array from a dec string public static System.Boolean DECStringToWord ( System.String strHex, ref System.UInt16 hwResult, System.Boolean bStrictCheck ) { UInt32 n = 0; UInt32 wResult = 0; Int32 Sign = 1; if (null == strHex) { return(false); } strHex = strHex.Trim(); strHex = strHex.ToUpper(); wResult = 0; if (strHex == "") { return(false); } if (strHex.StartsWith("-")) { Sign = -1; strHex = strHex.Remove(0, 1); } else if (strHex.StartsWith("+")) { //Sign = 1; strHex = strHex.Remove(0, 1); } while (strHex != "") { System.Byte chTemp = 0; if (strHex.StartsWith("0")) { chTemp = 0; } else if (strHex.StartsWith("1")) { chTemp = 1; } else if (strHex.StartsWith("2")) { chTemp = 2; } else if (strHex.StartsWith("3")) { chTemp = 3; } else if (strHex.StartsWith("4")) { chTemp = 4; } else if (strHex.StartsWith("5")) { chTemp = 5; } else if (strHex.StartsWith("6")) { chTemp = 6; } else if (strHex.StartsWith("7")) { chTemp = 7; } else if (strHex.StartsWith("8")) { chTemp = 8; } else if (strHex.StartsWith("9")) { chTemp = 9; } else { if (bStrictCheck) { return(false); } else if (n > 0) { return(true); } else { return(false); } } wResult *= 10; wResult += chTemp; n++; strHex = strHex.Remove(0, 1); } wResult = (UInt32)((Int32)wResult * Sign); if (Math.Abs((Int32)wResult) > 65535) { return(false); } hwResult = (UInt16)(wResult & 0xFFFF); return(true); }
//! get byte array from a hex string public static Boolean HEXStringToByteArray ( System.String strHex, ref System.Byte[] cResult, System.Boolean bStrictCheck ) { UInt32 n = 0; UInt32 wIndex = 0; Boolean bIfFindBlankSpace = true; List <Byte> tResultList = new List <Byte>(); if (null == strHex) { return(false); } tResultList.Add(new Byte()); /* * if (null == cResult) * { * cResult = new Byte[1]; * } */ strHex = strHex.Trim(); strHex = strHex.ToUpper(); if (strHex.StartsWith("0X")) { strHex = strHex.Remove(0, 2); } /* * if (cResult.Length < 1) * { * cResult = new Byte[1]; * } */ if (strHex == "") { return(false); } //cResult[0] = 0; String tOriginalString = strHex; UInt32 tCounter = 0; Boolean bFirstBlank = false; do { if (tCounter < tOriginalString.Length) { strHex = tOriginalString.Substring((Int32)tCounter, 1); } else { break; } Byte chTemp = 0; if (strHex.StartsWith("0")) { bIfFindBlankSpace = false; chTemp = 0; } else if (strHex.StartsWith("1")) { bIfFindBlankSpace = false; chTemp = 1; } else if (strHex.StartsWith("2")) { bIfFindBlankSpace = false; chTemp = 2; } else if (strHex.StartsWith("3")) { bIfFindBlankSpace = false; chTemp = 3; } else if (strHex.StartsWith("4")) { bIfFindBlankSpace = false; chTemp = 4; } else if (strHex.StartsWith("5")) { bIfFindBlankSpace = false; chTemp = 5; } else if (strHex.StartsWith("6")) { bIfFindBlankSpace = false; chTemp = 6; } else if (strHex.StartsWith("7")) { bIfFindBlankSpace = false; chTemp = 7; } else if (strHex.StartsWith("8")) { bIfFindBlankSpace = false; chTemp = 8; } else if (strHex.StartsWith("9")) { bIfFindBlankSpace = false; chTemp = 9; } else if (strHex.StartsWith("A")) { bIfFindBlankSpace = false; chTemp = 0x0A; } else if (strHex.StartsWith("B")) { bIfFindBlankSpace = false; chTemp = 0x0B; } else if (strHex.StartsWith("C")) { bIfFindBlankSpace = false; chTemp = 0x0C; } else if (strHex.StartsWith("D")) { bIfFindBlankSpace = false; chTemp = 0x0D; } else if (strHex.StartsWith("E")) { bIfFindBlankSpace = false; chTemp = 0x0E; } else if (strHex.StartsWith("F")) { bIfFindBlankSpace = false; chTemp = 0x0F; } else if (strHex.ToCharArray()[0] == 32) { if (false == bIfFindBlankSpace) { bIfFindBlankSpace = true; do { tCounter++; n++; wIndex = n >> 1; n = wIndex * 2; if (tCounter < tOriginalString.Length) { strHex = tOriginalString.Substring((Int32)tCounter, 1); } else { break; } } while (strHex.ToCharArray()[0] == 32); } //strHex = strHex.Remove(0, 1); continue; } else { if (bStrictCheck) { return(false); } else if (n > 0) { cResult = tResultList.ToArray(); return(true); } else { return(false); } } if (0 == (n % (sizeof(Byte) * 2))) { if (tResultList.Count <= wIndex) { tResultList.Add(new Byte()); //Array.Resize(ref cResult, cResult.Length + 1); } } tResultList[(Int32)wIndex] <<= 4; tResultList[(Int32)wIndex] |= chTemp; tCounter++; n++; wIndex = n >> 1; } while (strHex != ""); cResult = tResultList.ToArray(); return(true); }
static void Main(string[] args) { { int dec = 32; int hex = 0x2A; int bin = 0b_0010_1010; } { var a = 42.99; float b = 19.50f; System.Double c = -1.23; } { decimal a = 42.99m; var b = 12.45m; System.Decimal c = 100.75M; } { char a = 'A'; char b = '\x0065'; char c = '\u15FE'; } { string s1; // unitialized string s2 = null; // initialized with null string s3 = String.Empty; // empty string string s4 = "hello world"; // initialized with text var s5 = "hello world"; System.String s6 = "hello world"; char[] letters = { 'h', 'e', 'l', 'l', 'o' }; string s7 = new string(letters); // from an array of chars char c = s4[0]; // OK //s4[0] = 'H'; // error var s8 = s6.Remove(5); // hello var s9 = s6.ToUpper(); // HELLO WORLD } { int i = 42; double d = 19.99; var s1 = i.ToString(); var s2 = d.ToString(); } { int i = 42; string s1 = "This is item " + i.ToString(); string s2 = string.Format("This is item {0}", i); string s3 = $"This is item {i}"; string s4 = $@"This is item ""{i}"""; } { var s1 = "c:\\Program Files (x86)\\Windows Kits\\"; var s2 = "That was called a \"demo\""; var s3 = "This text\nspawns multiple lines."; } { var s1 = @"c:\Program Files (x86)\Windows Kits\"; var s2 = @"That was called a ""demo"""; var s3 = @"This text spawns multiple lines."; } { bool f; char ch = 'x'; int a, b = 20, c = 42; a = -1; f = true; } { for (int i = 1; i < 10; i++) { Console.WriteLine(i); } // i = 20; // i is out of scope } { int a = 5; for (int i = 1; i < 10; i++) { //char a = 'w'; // compile error if (i % 2 == 0) { Console.WriteLine(i + a); // a is within the scope of Main } } // i = 20; // i is out of scope } { int x = 42; object o = x; // boxing o = 43; int y = (int)o; // unboxing Console.WriteLine(x); // 42 Console.WriteLine(y); // 43 } { int?a; int?b = null; int?c = 42; if (c.HasValue) { Console.WriteLine(c.Value); } int d = c ?? -1; } { Nullable <int> a; Nullable <int> b = null; Nullable <int> c = 42; } { int[] arr1; int[] arr2 = null; int[] arr3 = new int[6]; int[] arr4 = new int[] { 1, 1, 2, 3, 5, 8 }; int[] arr5 = new int[6] { 1, 1, 2, 3, 5, 8 }; int[] arr6 = { 1, 1, 2, 3, 5, 8 }; for (int i = 0; i < arr6.Length; ++i) { Console.WriteLine(arr6[i]); } foreach (int element in arr6) { Console.WriteLine(element); } for (int i = 0; i < arr6.Length; ++i) { arr6[i] *= 2; // OK } //foreach (int element in arr6) // element *= 2; // error } { int[,] arr1; arr1 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } }; int[,] arr2 = null; int[,] arr3 = new int[2, 3]; int[,] arr4 = new int[, ] { { 1, 2, 3 }, { 4, 5, 6 } }; int[,] arr5 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } }; int[,] arr6 = { { 1, 2, 3 }, { 4, 5, 6 } }; for (int i = 0; i < arr6.GetLength(0); ++i) { for (int j = 0; j < arr6.GetLength(1); ++j) { Console.Write($"{arr6[i, j]} "); } Console.WriteLine(); } int[,,] arr7 = new int[4, 3, 2] { { { 11, 12 }, { 13, 14 }, { 15, 16 } }, { { 21, 22 }, { 23, 24 }, { 25, 26 } }, { { 31, 32 }, { 33, 34 }, { 35, 36 } }, { { 41, 42 }, { 43, 44 }, { 45, 46 } } }; } { int[][] arr1; int[][] arr2 = null; int[][] arr3 = new int[2][]; arr3[0] = new int[3]; arr3[1] = new int[] { 1, 1, 2, 3, 5, 8 }; int[][] arr4 = new int[][] { new int[] { 1, 2, 3 }, new int[] { 1, 1, 2, 3, 5, 8 } }; int[][] arr5 = { new int[] { 1, 2, 3 }, new int[] { 1, 1,2, 3, 5, 8 } }; int[][,] arr6 = new int[][, ] { new int[, ] { { 1, 2 }, { 3, 4 } }, new int[, ] { { 11, 12, 13 }, { 14, 15, 16 } } }; for (int i = 0; i < arr5.Length; ++i) { for (int j = 0; j < arr5[i].Length; ++j) { Console.Write($"{arr5[i][j]} "); } Console.WriteLine(); } } { int i = 10; float f = i; long l = 7195467872; double d = l; string s = "example"; object o = s; // implicit conversion string r = (string)o; // explicit conversion } { double d = 12.34; int i = (int)d; } { fancyint a = new fancyint(42); int i = a; // implicit conversion fancyint b = (fancyint)i; // explicit conversion } { DateTime dt1 = DateTime.Parse("2019.08.31"); DateTime.TryParse("2019.08.31", out DateTime dt2); int i1 = int.Parse("42"); try { int i2 = int.Parse("42.15"); } catch { } int.TryParse("42.15", out int i3); } { int a = 10; int b = a++; } { int a = 10; int b = ++a; } { bool a = true, b = false; bool c = a && b; bool d = a || !b; } { int a = 10; // 1010 int b = 5; // 0101 int c = a & b; // 0000 int d = a | b; // 1111 } { int x = 0b_0000_0110; x = x << 4; // 0b_0110_0000 Console.WriteLine(Convert.ToString(x, 2)); uint y = 0b_1111_0000_0000_0000_1111_1110_1100_1000; y = y << 2; // 0b_1100_0000_0000_0011_1111_1011_0010_0000; Console.WriteLine(Convert.ToString(y, 2)); } { int x = 0b_0000_0000; x = x >> 4; // 0b_0110_0000 Console.WriteLine(Convert.ToString(x, 2)); uint y = 0b_1111_0000_0000_0000_1111_1110_1100_1000; y = y >> 2; // 0b_0011_1100_0000_0000_0011_1111_1011_0010; Console.WriteLine(Convert.ToString(y, 2)); } { int a = 42; a = a + 11; // or a += 11; } }
//! get word array from a hex string public static Boolean HEXStringToU64Array ( System.String strHex, ref System.UInt64[] dwResult, System.Boolean bStrictCheck ) { UInt32 n = 0; if (null == strHex) { return(false); } if (null == dwResult) { dwResult = new UInt64[1]; } strHex = strHex.Trim(); strHex = strHex.ToUpper(); if (strHex.StartsWith("0X")) { strHex = strHex.Remove(0, 2); } if (dwResult.Length < 1) { Array.Resize(ref dwResult, 1); } dwResult[0] = 0; if (strHex == "") { return(false); } String tOriginalString = strHex; do { if (n < tOriginalString.Length) { strHex = tOriginalString.Substring((Int32)n, 1); } else { break; } if (0 == (n % (sizeof(UInt64) * 2))) { if (dwResult.Length <= (n >> 4)) { Array.Resize(ref dwResult, dwResult.Length + 1); } } System.Byte chTemp = 0; if (strHex.StartsWith("0")) { chTemp = 0; } else if (strHex.StartsWith("1")) { chTemp = 1; } else if (strHex.StartsWith("2")) { chTemp = 2; } else if (strHex.StartsWith("3")) { chTemp = 3; } else if (strHex.StartsWith("4")) { chTemp = 4; } else if (strHex.StartsWith("5")) { chTemp = 5; } else if (strHex.StartsWith("6")) { chTemp = 6; } else if (strHex.StartsWith("7")) { chTemp = 7; } else if (strHex.StartsWith("8")) { chTemp = 8; } else if (strHex.StartsWith("9")) { chTemp = 9; } else if (strHex.StartsWith("A")) { chTemp = 0x0A; } else if (strHex.StartsWith("B")) { chTemp = 0x0B; } else if (strHex.StartsWith("C")) { chTemp = 0x0C; } else if (strHex.StartsWith("D")) { chTemp = 0x0D; } else if (strHex.StartsWith("E")) { chTemp = 0x0E; } else if (strHex.StartsWith("F")) { chTemp = 0x0F; } else { if (bStrictCheck) { return(false); } else if (n > 0) { return(true); } else { return(false); } } dwResult[n >> 4] <<= 4; dwResult[n >> 4] |= chTemp; n++; //strHex = strHex.Remove(0, 1); } while (strHex != ""); return(true); }
/// <summary> /// Remove first character from String /// </summary> /// <param name="entity">String</param> /// <returns></returns> public static string RemoveFirstCharacter(this System.String entity) { return(String.IsNullOrWhiteSpace(entity) ? String.Empty : entity.Remove(0, 1)); }