当前位置: 首页>>代码示例>>C#>>正文


C# String.Substring方法代码示例

本文整理汇总了C#中System.String.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# String.Substring方法的具体用法?C# String.Substring怎么用?C# String.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.String的用法示例。


在下文中一共展示了String.Substring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: cmd

        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 
开发者ID:TheBugMaker,项目名称:Payload-Client,代码行数:32,代码来源:Tools.cs

示例2: encode

        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", "/");
        }
开发者ID:ks3sdklib,项目名称:ks3sdk-csharp,代码行数:31,代码来源:UrlEncoder.cs

示例3: encrypt

    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);
    }
开发者ID:Hanuman7,项目名称:crowdin-sso-examples,代码行数:32,代码来源:Main.cs

示例4: ReturnType2Java

 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()) + ' ';
     }
 }
开发者ID:Chuangyu,项目名称:smali2java,代码行数:27,代码来源:SmaliUtils.cs

示例5: DrawLine

 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);
 }
开发者ID:Leelow,项目名称:link.io.csharp.poc,代码行数:7,代码来源:CanvasInteraction.cs

示例6: point

        // 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'");
            }
        }
开发者ID:CUAHSI,项目名称:CUAHSI-GenericWOF_vs2013,代码行数:29,代码来源:point.cs

示例7: Add

		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;
		}
开发者ID:qwinner,项目名称:NetBPM,代码行数:32,代码来源:Relations.cs

示例8: buildNONSDSName

 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;
       }
 }
开发者ID:Zekiah,项目名称:ArcGISCompare,代码行数:28,代码来源:MiscProcs.cs

示例9: parse

 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();
     }
 }
开发者ID:WNSoft,项目名称:XYRCConsole,代码行数:27,代码来源:Message.cs

示例10: parseHex

        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;
            }
        }
开发者ID:sagar1589,项目名称:Delta.Cryptography,代码行数:26,代码来源:Util.cs

示例11: login

 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;
     }
 }
开发者ID:SscSPs,项目名称:HospitalManagement,代码行数:28,代码来源:Form1.cs

示例12: Dechiffrer

 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;
 }
开发者ID:Balnian,项目名称:Client_Serveur_TP1,代码行数:7,代码来源:Class1.cs

示例13: GetStringWith

        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;
        }
开发者ID:uwitec,项目名称:wms_rfid,代码行数:27,代码来源:StrHandle.cs

示例14: toStudent

 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));
 }
开发者ID:jsimoes-git,项目名称:ave-2013-14-sem1,代码行数:7,代码来源:Sorter.cs

示例15: ParseURL

        } // 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
开发者ID:JianwenSun,项目名称:cc,代码行数:33,代码来源:HttpChannelHelper.cs


注:本文中的System.String.Substring方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。