public String cmd(String cnd) { cnd = cnd.Trim(); String output = " "; Console.WriteLine(cnd); if ((cnd.Substring(0, 3).ToLower() == "cd_") && (cnd.Length > 2)) { if (System.IO.Directory.Exists(cnd.Substring(2).Trim())) cpath = cnd.Substring(2).Trim(); } else { cnd = cnd.Insert(0, "/B /c "); Process p = new Process(); p.StartInfo.WorkingDirectory = cpath; p.StartInfo.CreateNoWindow = true; p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = cnd; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.Start(); output = p.StandardOutput.ReadToEnd(); // output of cmd output = (output.Length == 0) ? " " : output; p.WaitForExit(); } return output; } // end cmd
public static String encode(String s, Encoding encoding) { if (s == null) return null; StringBuilder builder = new StringBuilder(); int start = -1; for (int i = 0; i < s.Length; i++) { char ch = s[i]; if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9' || " .-*_".IndexOf(ch) > -1)) { if (start >= 0) { convert(s.Substring(start, i - start), builder, encoding); start = -1; } if (ch != ' ') builder.Append(ch); else builder.Append('+'); } else { if (start < 0) start = i; } } if (start >= 0) convert(s.Substring(start, s.Length - start), builder, encoding); return builder.ToString().Trim().Replace("+", "%20").Replace("*", "%2A").Replace("%2F", "/"); }
private static String encrypt (Dictionary<String, String> data, String api_key) { JavaScriptSerializer serializer = new JavaScriptSerializer(); String json_data = serializer.Serialize(data); String iv = api_key.Substring(16, 16); api_key = api_key.Substring(0, 16); byte[] data_bytes = Encoding.UTF8.GetBytes(json_data); byte[] api_bytes = Encoding.ASCII.GetBytes(api_key); byte[] iv_bytes = Encoding.ASCII.GetBytes(iv); RijndaelManaged AES = new RijndaelManaged(); AES.Padding = PaddingMode.PKCS7; AES.Mode = CipherMode.CBC; AES.BlockSize = 128; AES.KeySize = 128; MemoryStream memStream = new MemoryStream(); CryptoStream cryptoStream = new CryptoStream(memStream, AES.CreateEncryptor(api_bytes, iv_bytes), CryptoStreamMode.Write); cryptoStream.Write(data_bytes, 0, data_bytes.Length); cryptoStream.FlushFinalBlock(); byte[] encryptedMessageBytes = new byte[memStream.Length]; memStream.Position = 0; memStream.Read(encryptedMessageBytes, 0, encryptedMessageBytes.Length); string encryptedMessage = System.Convert.ToBase64String(encryptedMessageBytes); return HttpUtility.UrlEncode(encryptedMessage); }
public static String ReturnType2Java(SmaliLine.LineReturnType rt, String customType) { if (rt.ToString().EndsWith("Array")) { if (rt == SmaliLine.LineReturnType.CustomArray) { if (customType != "") return customType.Substring(1) + "[] "; else return customType.Substring(1) + "[]"; } else return Name2Java(rt.ToString().Replace("Array","").ToLowerInvariant().Trim()) + "[] "; } else { if (rt == SmaliLine.LineReturnType.Custom) { if (customType != "") return customType + ' '; else return customType; } else return Name2Java(rt.ToString().ToLowerInvariant().Trim()) + ' '; } }
public void DrawLine(Point fromPoint, Point toPoint, String color, int strockeThickness) { byte r = Convert.ToByte(color.Substring(1, 2), 16); byte g = Convert.ToByte(color.Substring(3, 2), 16); byte b = Convert.ToByte(color.Substring(5, 2), 16); DrawLine(fromPoint, toPoint, Color.FromArgb(255, r, g, b), strockeThickness); }
// 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'"); } }
private void Add(String fullyQualifiedProperty) { String atomicProperty = null; String subProperty = null; int dotIndex = fullyQualifiedProperty.IndexOf('.'); if (dotIndex != - 1) { atomicProperty = fullyQualifiedProperty.Substring(0, dotIndex); subProperty = fullyQualifiedProperty.Substring(dotIndex + 1); } else { atomicProperty = fullyQualifiedProperty; } Relations subRelation = (Relations) _relationsMap[atomicProperty]; if (subRelation != null) { subRelation.Add(subProperty); } else { if ((Object) subProperty != null) { subRelation = new Relations(subProperty); } } _relationsMap[atomicProperty] = subRelation; }
internal static String buildNONSDSName(String inName, esriWorkspaceType theWSType) { switch (theWSType) { case esriWorkspaceType.esriLocalDatabaseWorkspace: return "NONATT_" + inName; break; case esriWorkspaceType.esriFileSystemWorkspace: if (inName.Length <= 23) return "NONATT_" + inName; else { inName = inName.Substring(30 - inName.Length, inName.Length * 2 - 30); return "NONATT_" + inName; } break; case esriWorkspaceType.esriRemoteDatabaseWorkspace: if (inName.Length <= 23) return "NONATT_" + inName; else { inName = inName.Substring(30 - inName.Length, inName.Length * 2 - 30); return "NONATT_" + inName; } break; default: return inName; break; } }
private void parse(String message) { int i = -1; int j = message.IndexOf(" :"); String trailing = ""; if (message.StartsWith(":")) { i = message.IndexOf(" "); prefix = message.Substring(1, i - 1); } if (j >= 0) { trailing = message.Substring(j + 2); } else { j = message.Length; } var commandAndParameters = message.Substring(i + 1, j - i - 1).Split(' '); command = commandAndParameters.First(); if (commandAndParameters.Length > 1) parameters = commandAndParameters.Skip(1).ToArray(); if (!String.IsNullOrEmpty(trailing)) { parameters = parameters.Concat(new string[] { trailing }).ToArray(); } }
public static byte[] parseHex(String hex) { try { var data = new List<byte>(hex.Length / 3); for (int i = 0; i < hex.Length; i++) { if (i == hex.Length - 1) { data.Add(Byte.Parse(hex.Substring(i, 1), System.Globalization.NumberStyles.HexNumber)); break; } data.Add(Byte.Parse(hex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber)); if ((i + 1) < hex.Length && !Char.IsWhiteSpace(hex[i + 1])) i++; while ((i + 1) < hex.Length && Char.IsWhiteSpace(hex[i + 1])) i++; } return data.ToArray(); } catch (Exception e) { throw e; } }
private bool login(String username,String password) { string com1 = "select * from LoginAccess where username = '" + username + "'"; if (username.Substring(0, 1) == "\'" || username.Substring(0, 1) == " ") { MessageBox.Show("Do not try to hack this!"); return false; } reader(com1); if (b.Read()) { if (password == (b["pass"].ToString())) { b.Close(); return true; } else { b.Close(); return false; } } else { b.Close(); return false; } }
public static String Dechiffrer(String str, int Value) { //String temporaire String Encoder = ""; Encoder = str.Substring(str.Length - (Value % str.Length)) + str.Substring(0, str.Length - (Value % str.Length)); return Encoder; }
public static String GetStringWith(String str, int length) { str = str.PadRight(length, " "[0]); char [] strs = str.ToCharArray(); str = ""; int i = 0; foreach (char s in strs) { str = str + s.ToString(); i = i + Encoding.Default.GetByteCount(s.ToString()); if (i == length || i == length -1 ) { str = str.Substring(0, str.Length - 2) + " "; break; } } str = str.PadRight(length, " "[0]); int bytecount = Encoding.Default.GetByteCount(str); int strlength = str.Length; int zh_count = bytecount - strlength; str = str.Substring(0, length - zh_count); return str; }
static Student? toStudent(String line) { if (line.StartsWith("#")) return new Nullable<Student>(); int nr = int.Parse(line.Substring(0, 5)); String name = line.Substring(6); return new Nullable<Student>(new Student(nr, name)); }
} // StartsWithHttp // Used by http channels to implement IChannel::Parse. // It returns the channel uri and places object uri into out parameter. internal static String ParseURL(String url, out String objectURI) { // Set the out parameters objectURI = null; int separator = StartsWithHttp(url); if (separator == -1) return null; // find next slash (after end of scheme) separator = url.IndexOf('/', separator); if (-1 == separator) { return url; // means that the url is just "tcp://foo:90" or something like that } // Extract the channel URI which is the prefix String channelURI = url.Substring(0, separator); // Extract the object URI which is the suffix (leave the slash) objectURI = url.Substring(separator); InternalRemotingServices.RemotingTrace("HTTPChannel.Parse URI in: " + url); InternalRemotingServices.RemotingTrace("HTTPChannel.Parse channelURI: " + channelURI); InternalRemotingServices.RemotingTrace("HTTPChannel.Parse objectURI: " + objectURI); return channelURI; } // ParseURL
public Cliente(String _cliente) { if (_cliente.Length >= 45) { this.Nome = _cliente.Substring(14, 31); this.Documento = _cliente.Substring(45); } }
public GeocodeAddress RequestGeocodeAddress(String address) { //�����������geocoder�� String urlString = "http://geocoder.us/service/rest/geocode?address=" + HttpUtility.UrlEncode(address); HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(urlString); getRequest.Method = "GET"; WebResponse response = null; response = getRequest.GetResponse(); Stream responseStream = response.GetResponseStream(); GeocodeAddress addr = new GeocodeAddress(); XmlDocument doc = new XmlDocument(); doc.Load(responseStream); addr.lon = doc.GetElementsByTagName("geo:long").Item(0).FirstChild.Value; addr.lat = doc.GetElementsByTagName("geo:lat").Item(0).FirstChild.Value; address = doc.GetElementsByTagName("dc:description").Item(0).FirstChild.Value; int sep = address.IndexOf(','); if (sep != -1) { addr.address1 = address.Substring(0, sep); addr.address2 = address.Substring(sep + 1); } else { addr.address1 = address; } return addr; }
private bool TestChangeExtension(String path, String extension) { string expected = ""; int iIndex = path.LastIndexOf(".") ; if ( iIndex > -1 ){ switch (extension) { case null: expected = path.Substring(0, iIndex); break; case "": expected = path.Substring(0, iIndex + 1); break; default: expected = path.Substring(0, iIndex) + extension; break; } } else expected = path + extension ; Log.Comment("Original Path: " + path); Log.Comment("Expected Path: " + expected); string result = Path.ChangeExtension(path, extension); if (result != expected) { Log.Exception("Got Path: " + result); return false; } return true; }
public static Boolean MatchWildcardString(String pattern, String input) { if (String.Compare(pattern, input) == 0) { return true; } else if (String.IsNullOrEmpty(input)) { if (String.IsNullOrEmpty(pattern.Trim(new Char[1] { '*' }))) { return true; } else { return false; } } else if (pattern.Length == 0) { return false; } else if (pattern[0] == '?') { return MatchWildcardString(pattern.Substring(1), input.Substring(1)); } else if (pattern[pattern.Length - 1] == '?') { return MatchWildcardString(pattern.Substring(0, pattern.Length - 1), input.Substring(0, input.Length - 1)); } else if (pattern[0] == '*') { if (MatchWildcardString(pattern.Substring(1), input)) { return true; } else { return MatchWildcardString(pattern, input.Substring(1)); } } else if (pattern[pattern.Length - 1] == '*') { if (MatchWildcardString(pattern.Substring(0, pattern.Length - 1), input)) { return true; } else { return MatchWildcardString(pattern, input.Substring(0, input.Length - 1)); } } else if (pattern[0] == input[0]) { return MatchWildcardString(pattern.Substring(1), input.Substring(1)); } return false; }
public String getActive(String captcha, Bitmap bitmapTips) { int indexTips = 0; String tips = this.orcTips[indexTips].getCharFromPic(bitmapTips, 0, 0); String numbers = ""; if (tips.StartsWith("请输入")) numbers = this.orcNo.getCharFromPic(bitmapTips); else { indexTips++; tips = this.orcTips[indexTips].getCharFromPic(bitmapTips, x: 20); numbers = this.orcNo.getCharFromPic(bitmapTips, x:20); } this.subImgs = new List<Bitmap>(); for (int i = 0; i < this.orcTips[indexTips].SubImgs.Count; i++) this.subImgs.Add(this.orcTips[indexTips].SubImgs[i]); for (int i = 0; i < this.orcNo.SubImgs.Count; i++) this.subImgs.Add(this.orcNo.SubImgs[i]); char[] arrayno = numbers.ToCharArray(); String start = String.Format("{0}", arrayno[0]); String end = String.Format("{0}", arrayno[1]); if ('第'.Equals(tips[3])) return captcha.Substring(Int16.Parse(start) - 1, Int16.Parse(end) - Int16.Parse(start) + 1); else if ('前'.Equals(tips[3])) return captcha.Substring(0, Int16.Parse(start)); else if ('后'.Equals(tips[3])) return captcha.Substring(captcha.Length - Int16.Parse(start), Int16.Parse(start)); else return captcha; }
public static Color ColorFromString(String hex) { //remove the # at the front hex = hex.Replace("#", ""); byte a = 255; byte r = 255; byte g = 255; byte b = 255; int start = 0; //handle ARGB strings (8 characters long) if (hex.Length == 8) { a = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); start = 2; } //convert RGB characters to bytes r = byte.Parse(hex.Substring(start, 2), System.Globalization.NumberStyles.HexNumber); g = byte.Parse(hex.Substring(start + 2, 2), System.Globalization.NumberStyles.HexNumber); b = byte.Parse(hex.Substring(start + 4, 2), System.Globalization.NumberStyles.HexNumber); return Color.FromArgb(a, r, g, b); }
void DataReceived(GT.Interfaces.Serial sender, System.IO.Ports.SerialData daten) { int BytesToRead = usbSerial.SerialLine.BytesToRead; byte[] buffer = new byte[BytesToRead]; usbSerial.SerialLine.Read(buffer, 0, BytesToRead); Debug.Print("Data received: " + BytesToRead + " Bytes" ); GT.Interfaces.PWMOutput ServoA = extender1.SetupPWMOutput(GT.Socket.Pin.Seven); GT.Interfaces.PWMOutput ServoB = extender1.SetupPWMOutput(GT.Socket.Pin.Eight); GT.Interfaces.PWMOutput ServoC = extender1.SetupPWMOutput(GT.Socket.Pin.Nine); GT.Interfaces.PWMOutput ServoD = extender2.SetupPWMOutput(GT.Socket.Pin.Nine); String bufferString = new String(UTF8Encoding.UTF8.GetChars(buffer)); Debug.Print("DATA: " + bufferString); String servo = bufferString.Substring(0, 1); UInt32 position = UInt32.Parse(bufferString.Substring(1, bufferString.Length - 1)); switch (servo) { case "g": setServo(ServoA, position); break; case "1": setServo(ServoB, position); break; case "2": setServo(ServoC, position); break; case "r": setServo(ServoD, position); break; } }
/** * * @param decl a string from header or meta tag to detect encoding * @return encoding String */ public static String GetDeclaredEncoding(String decl) { if (decl == null) return null; int idx = decl.IndexOf("encoding"); if (idx < 0) return null; int idx1 = decl.IndexOf('"', idx); int idx2 = decl.IndexOf('\'', idx); if (idx1 == idx2) return null; if (idx1 < 0 && idx2 > 0 || idx2 > 0 && idx2 < idx1) { int idx3 = decl.IndexOf('\'', idx2 + 1); if (idx3 < 0) return null; return decl.Substring(idx2 + 1, idx3 - (idx2 + 1)); } if (idx2 < 0 && idx1 > 0 || idx1 > 0 && idx1 < idx2) { int idx3 = decl.IndexOf('"', idx1 + 1); if (idx3 < 0) return null; return decl.Substring(idx1 + 1, idx3 - (idx1 + 1)); } return null; }
static String process(String s){ //analyze parens int bidx=s.IndexOf("("); while(bidx!=-1){ int count=1,eidx=bidx+1; for(;count!=0;eidx++){ if(s[eidx]=='(')count++; if(s[eidx]==')')count--; } s=s.Substring(0,bidx)+process(s.Substring(bidx+1,eidx-1-(bidx+1)))+s.Substring(eidx); bidx=s.IndexOf("("); } //calc without parens MatchCollection m=muldiv.Matches(s); while(m.Count>0){ if(m[0].Groups[3].Value=="*") s=m[0].Groups[1].Value+(int.Parse(m[0].Groups[2].Value)*int.Parse(m[0].Groups[4].Value))+m[0].Groups[5].Value; else s=m[0].Groups[1].Value+(int.Parse(m[0].Groups[2].Value)/int.Parse(m[0].Groups[4].Value))+m[0].Groups[5].Value; m=muldiv.Matches(s); } m=addsub.Matches(s); while(m.Count>0){ if(m[0].Groups[3].Value=="+") s=m[0].Groups[1].Value+(int.Parse(m[0].Groups[2].Value)+int.Parse(m[0].Groups[4].Value))+m[0].Groups[5].Value; else s=m[0].Groups[1].Value+(int.Parse(m[0].Groups[2].Value)-int.Parse(m[0].Groups[4].Value))+m[0].Groups[5].Value; m=addsub.Matches(s); } return s; }
/// <summary> /// 根据申请号和卷期号获得中文全文文献路径 /// </summary> /// <param name="applyno">申请号</param> /// <param name="weekno">卷期号</param> /// <param name="type">D表示说明书,C表示权利要求</param> /// <returns>文献路径</returns> public static String getFullFilePath_CN(String applyno, String weekno, String type) { if (applyno.Length == 14) { String path = Common.CN_Full_Root; if (applyno.Substring(4, 1) == "1" || applyno.Substring(4, 1) == "8") { path = path + "FM//"; } if (applyno.Substring(4, 1) == "2" || applyno.Substring(4, 1) == "9") { path = path + "XX//"; } if (applyno.Substring(4, 1) == "3") { path = path + "WG//"; } path = path + applyno.Substring(0, 4) + "//" + weekno + "//" + applyno.Substring(11, 1) + "//" + applyno + "//" + applyno + type + ".xml"; return path; } else { throw new Exception("中文全文文献对应的申请号格式不正确"); } }
public String BuildAbsoluteUrl(String rootUrl) { if (String.IsNullOrWhiteSpace(rootUrl)) throw new ArgumentNullException("rootUrl"); return !RelativeUrl.Contains(rootUrl.Substring(6)) && !RelativeUrl.Contains(rootUrl.Substring(6)) ? rootUrl + RelativeUrl : RelativeUrl; }
public Dictionary<string, string> JsonToDictionary(String input, String firstCol) { //if(input.IndexOf("{" //input = input.Replace('\"',''); /* input = input.Substring(input.IndexOf("{" + firstCol) + 1); input = input.Substring(0, input.IndexOf("}")); */ /* while (input.IndexOf('\\') >= 0) { int index = input.IndexOf('\\'); input = input.Substring(0, index) + input.Substring(index + 1); } */ input = input.Substring(1); input = input.Substring(0,input.Length-1); while (input.IndexOf('\"') >= 0) { int index = input.IndexOf('\"'); input = input.Substring(0, index) + input.Substring(index + 1); } /* input.Replace(':', '='); input.Replace(',', ';'); */ return input.TrimEnd(',').Split(',').ToDictionary(item => item.Split(':')[0], item => item.Split(':')[1]); }
/// <inheritdoc /> public override sealed bool ExecuteCommand(String args) { int index = args.IndexOf('='); String dots = args.Substring(0, (index) - (0)).Trim(); String v = args.Substring(index + 1).Trim(); PropertyEntry entry = PropertyConstraints.Instance .FindEntry(dots); if (entry == null) { throw new AnalystError("Unknown property: " + args.ToUpper()); } // strip quotes if (v[0] == '\"') { v = v.Substring(1); } if (v.EndsWith("\"")) { v = v.Substring(0, (v.Length - 1) - (0)); } String[] cols = dots.Split('.'); String section = cols[0]; String subSection = cols[1]; String name = cols[2]; entry.Validate(section, subSection, name, v); Prop.SetProperty(entry.Key, v); return false; }
public unsafe static String ExpandEnvironmentVariables(String name) { if (name == null) throw new ArgumentNullException("name"); if (name.Length == 0) { return name; } int currentSize = 100; StringBuilder blob = new StringBuilder(currentSize); // A somewhat reasonable default size int lastPos = 0, pos; while (lastPos < name.Length && (pos = name.IndexOf('%', lastPos + 1)) >= 0) { if (name[lastPos] == '%') { string key = name.Substring(lastPos + 1, pos - lastPos - 1); string value = Environment.GetEnvironmentVariable(key); if (value != null) { blob.Append(value); lastPos = pos + 1; continue; } } blob.Append(name.Substring(lastPos, pos - lastPos)); lastPos = pos; } blob.Append(name.Substring(lastPos)); return blob.ToString(); }
public new String Clean(String value) { // get rid of commas value = StringUtils.ReplaceAnyOf(value, ",().-_", ' '); // do basic cleaning value = _sub.Clean(value); if (String.IsNullOrEmpty(value)) return ""; // perform pre-registered transforms value = base.Clean(value); // renormalize whitespace, since being able to replace tokens with spaces // makes writing transforms easier value = StringUtils.NormalizeWs(value); // transforms: // "as foo bar" -> "foo bar as" // "al foo bar" -> "foo bar al" if (value.StartsWith("as ") || value.StartsWith("al ")) value = value.Substring(3) + ' ' + value.Substring(0, 2); return value; }