Remove() public method

public Remove ( int startIndex, int length ) : StringBuilder
startIndex int
length int
return StringBuilder
Example #1
1
        static void Main()
        {
            string inputStr = Console.ReadLine();
            string multipleString = "";
            while (inputStr != "END")
            {
                multipleString += inputStr;
                inputStr = Console.ReadLine();
            }
            string pattern = @"(?<=<a).*?\s*href\s*=\s*((""[^""]*""(?=>))|('[^']*'(?=>))|([\w\/\:\.]+\.\w{3})|(\/[^'""]*?(?=>)))";
               //string pattern = @"(?s)(?:<a)(?:[\s\n_0-9a-zA-Z=""()]*?.*?)(?:href([\s\n]*)?=(?:['""\s\n]*)?)([a-zA-Z:#\/._\-0-9!?=^+]*(\([""'a-zA-Z\s.()0-9]*\))?)(?:[\s\na-zA-Z=""()0-9]*.*?)?(?:\>)";
            MatchCollection collection = Regex.Matches(multipleString, pattern);
            List<string> resultStrings = new List<string>();
            foreach (Match match in collection)
            {
                StringBuilder tempStr = new StringBuilder(match.Groups[2].Value);
                if (tempStr[0] == '"' || tempStr[0] == '\'')
                {
                    tempStr.Remove(0,1);
                }
                if (tempStr[tempStr.Length-1] == '"' || tempStr[tempStr.Length-1] == '\'')
                {
                    tempStr.Remove(tempStr.Length-1,1);
                }
                resultStrings.Add(tempStr.ToString());
                Console.WriteLine(tempStr);

            }
            //Console.WriteLine(string.Join("\r\n",resultStrings));
        }
Example #2
0
        /// <summary>
        /// Converts input phone string to its canonical variant.
        /// </summary>
        /// <param name="phoneNumberString">Phone number string.</param> 
        /// <returns>Converted phone string.</returns>
        private static string ConvertToCanonical(string phoneNumberString)
        {
            var resultNumber = new StringBuilder();

            resultNumber.Clear();
            foreach (char character in phoneNumberString)
            {
                if (char.IsDigit(character) || (character == '+'))
                {
                    resultNumber.Append(character);
                }
            }
            if (resultNumber.Length >= 2 && resultNumber[0] == '0' && resultNumber[1] == '0')
            {
                resultNumber.Remove(0, 1);
                resultNumber[0] = '+';
            }
            while (resultNumber.Length > 0 && resultNumber[0] == '0')
            {
                resultNumber.Remove(0, 1);
            }
            if (resultNumber.Length > 0 && resultNumber[0] != '+')
            {
                resultNumber.Insert(0, DefaultCountryCode);
            }

            return resultNumber.ToString();
        }
        private static string ConvertToCanonical(string number)
        {
            StringBuilder sb = new StringBuilder();

                foreach (char ch in number)
                {
                    if (char.IsDigit(ch) || (ch == '+'))
                    {
                        sb.Append(ch);
                    }
                }

                if (sb.Length >= 2 && sb[0] == '0' && sb[1] == '0')
                {
                    sb.Remove(0, 1);
                    sb[0] = '+';
                }

                while (sb.Length > 0 && sb[0] == '0')
                {
                    sb.Remove(0, 1);
                }

                if (sb.Length > 0 && sb[0] != '+')
                {
                    sb.Insert(0, code);
                }

            return sb.ToString();
        }
        public byte[] ToBytes()
        {
            int totalLen = 0;
            byte[] bytes = new byte[TOTAL_WIDTH];
            StringBuilder sb = new StringBuilder();
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthString(RecordID, 8));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthFigure(RecordLength, 8));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthFigure(RecordNumber, 8));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            if (RecordCollection != null)
            {
                foreach (var record in RecordCollection)
                {
                    Array.Copy(record.ToBytes(), 0, bytes, totalLen, record.TOTAL_WIDTH);
                    totalLen += record.TOTAL_WIDTH;
                }                
            }
            return bytes;

        }
Example #5
0
	private static string CreateInsertSqlString(Table table, IDictionary<string, object> parameters)
	{
		var sb = new StringBuilder();
		sb.AppendLine("IF NOT EXISTS (SELECT * FROM {0} WHERE {1})".Put(table.Name, table.Columns.Where(c => c.IsPrimaryKey).Select(c => "{0} = @{0}".Put(c.Name)).Join(" AND ")));
		sb.AppendLine("BEGIN");
		sb.Append("INSERT INTO ");
		sb.Append(table.Name);
		sb.Append(" (");
		foreach (var par in parameters)
		{
			sb.Append("[");
			sb.Append(par.Key);
			sb.Append("],");
		}
		sb.Remove(sb.Length - 1, 1);
		sb.Append(") VALUES (");
		foreach (var par in parameters)
		{
			sb.Append("@");
			sb.Append(par.Key);
			sb.Append(",");
		}
		sb.Remove(sb.Length - 1, 1);
		sb.AppendLine(")");
		sb.Append("END");
		return sb.ToString();
	}
Example #6
0
 /// <summary>  
 /// dataTable转换成Json格式  
 /// </summary>  
 /// <param name="dt"></param>  
 /// <returns></returns>  
 public static string DataTable2Json(DataTable dt)
 {
     StringBuilder jsonBuilder = new StringBuilder();
     jsonBuilder.Append("{\"");
     jsonBuilder.Append(dt.TableName);
     jsonBuilder.Append("\":[");
     //jsonBuilder.Append("[");
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         jsonBuilder.Append("{");
         for (int j = 0; j < dt.Columns.Count; j++)
         {
             jsonBuilder.Append("\"");
             jsonBuilder.Append(dt.Columns[j].ColumnName);
             jsonBuilder.Append("\":\"");
             jsonBuilder.Append(dt.Rows[i][j].ToString());
             jsonBuilder.Append("\",");
         }
         jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
         jsonBuilder.Append("},");
     }
     jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
     jsonBuilder.Append("]");
     jsonBuilder.Append("}");
     return jsonBuilder.ToString();
 }
Example #7
0
		/// <summary>
		/// Detects untokenized fields and sets as NotAnalyzed in analyzer
		/// </summary>
		private static string PreProcessUntokenizedTerms(PerFieldAnalyzerWrapper analyzer, string query, Analyzer keywordAnlyzer)
		{
			var untokenizedMatches = untokenizedQuery.Matches(query);
			if (untokenizedMatches.Count < 1)
			{
				return query;
			}

			var sb = new StringBuilder(query);

			// KeywordAnalyzer will not tokenize the values

			// process in reverse order to leverage match string indexes
			for (int i=untokenizedMatches.Count; i>0; i--)
			{
				Match match = untokenizedMatches[i-1];

				// specify that term for this field should not be tokenized
				analyzer.AddAnalyzer(match.Groups[1].Value, keywordAnlyzer);

				Group term = match.Groups[2];

				// remove enclosing "[[" "]]" from term value (again in reverse order)
				sb.Remove(term.Index+term.Length-2, 2);
				sb.Remove(term.Index, 2);
			}

			return sb.ToString();
		}
        /// <summary>
        /// Arma los filtros que se aplicarán para regenerar
        /// el reporte. Depende de cada implementación del 
        /// IPanelFiltros.
        /// </summary>
        private string armaFiltro()
        {
            var sb = new StringBuilder();

            // Filtros de fecha
            // Si no selecciona ningún filtro, genera una excepción.
            if (chkListaEntidades.CheckedItems.Count != 0 &&
                chkEstadosGestion.CheckedItems.Count != 0)
            {
                // Filtros de entidades
                sb.Append("(");
                foreach (object item in chkListaEntidades.CheckedItems)
                    sb.Append(string.Format("Entidad = '{0}' or ", item));
                sb.Remove(sb.Length - 4, 4);
                sb.Append(")");

                // Filtros de estados de cuenta
                sb.Append(" and (");
                foreach (object item in chkEstadosGestion.CheckedItems)
                    sb.Append(string.Format("Estado = '{0}' or ", item));
                sb.Remove(sb.Length - 4, 4);
                sb.Append(")");

                return sb.ToString();
            }

            throw new Exception(Mensaje.TextoMensaje("REPORTE-NOFILTRO"));
        }
        /*
         * 插入新供应商
         */
        public void insertSupplier(Dictionary<String,String> supplierInformationDict)
        {
            StringBuilder sqlText = new StringBuilder("insert into supplier(");
            foreach (var item in supplierInformationDict)
            {
                sqlText.Append(item.Key);
                sqlText.Append(",");
            }
            sqlText.Remove(sqlText.Length-1,1);     //移除,(多余的逗号)
            sqlText.Append(") values(");

            SqlParameter[] sqlParameter = new SqlParameter[supplierInformationDict.Count];
            int index = 0;
            foreach (var item in supplierInformationDict)
            {
                sqlText.Append("@");
                sqlText.Append(item.Key);
                sqlText.Append(",");

                if (index != supplierInformationDict.Count - 1)
                {
                    sqlParameter[index] = new SqlParameter("@" + item.Key, SqlDbType.VarChar);
                }
                else
                {
                    sqlParameter[index] = new SqlParameter("@" + item.Key, SqlDbType.DateTime);
                }
                sqlParameter[index].Value = item.Value;
                index++;
            }
            sqlText.Remove(sqlText.Length - 1, 1);     //移除,(多余的逗号)
            sqlText.Append(")");

            DBHelper.ExecuteNonQuery(sqlText.ToString(),sqlParameter);
        }
Example #10
0
 private static StringBuilder MoveToBack(StringBuilder test, Tuple<int, int> location){
     var charToMoveToBack = test[location.Item1];
     test = test.Remove(location.Item1, 1);
     test = test.Remove(location.Item2 - 1, 1);
     test = test.Append(charToMoveToBack.ToString());
     return test;
 }
        /// <summary>Creates a regular expression that represents a comma-delimited list of the given regular expression pattern.</summary>
        /// <param name="expression">The regular expression.</param>
        /// <returns>A new regular expression.</returns>
        private static string CreateListRegularExpression(string expression)
        {
            var emailRegularExpressionBuilder = new StringBuilder(expression);
            var prefixBuilder = new StringBuilder();
            if (emailRegularExpressionBuilder[0] == '^')
            {
                prefixBuilder.Append('^');
                emailRegularExpressionBuilder.Remove(0, 1);
            }

            if (emailRegularExpressionBuilder.ToString(0, 2).Equals(@"\b", StringComparison.Ordinal))
            {
                prefixBuilder.Append(@"\b");
                emailRegularExpressionBuilder.Remove(0, 2);
            }

            var suffixBuilder = new StringBuilder();
            if (emailRegularExpressionBuilder[emailRegularExpressionBuilder.Length - 1] == '$')
            {
                suffixBuilder.Append('$');
                emailRegularExpressionBuilder.Remove(emailRegularExpressionBuilder.Length - 1, 1);
            }

            if (emailRegularExpressionBuilder.ToString(emailRegularExpressionBuilder.Length - 2, 2)
                                             .Equals(@"\b", StringComparison.Ordinal))
            {
                suffixBuilder.Append(@"\b");
                emailRegularExpressionBuilder.Remove(emailRegularExpressionBuilder.Length - 2, 2);
            }

            return string.Format(CultureInfo.InvariantCulture, @"{0}{1}(?:,\s*{1})*{2}", prefixBuilder, emailRegularExpressionBuilder, suffixBuilder);
        }
Example #12
0
 private static string BuildName(List<ObjectCommandPropertyValue> propValues)
 {
     StringBuilder builder = new StringBuilder();
     foreach (ObjectCommandPropertyValue value2 in propValues)
     {
         if ((value2 != null) && (value2.PropertyValue != null))
         {
             ICollection propertyValue = value2.PropertyValue as ICollection;
             if (propertyValue != null)
             {
                 builder.Append("{");
                 int length = builder.Length;
                 foreach (object obj2 in propertyValue)
                 {
                     builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}, ", new object[] { obj2.ToString() }));
                 }
                 builder = (builder.Length > length) ? builder.Remove(builder.Length - 2, 2) : builder;
                 builder.Append("}, ");
             }
             else
             {
                 builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}, ", new object[] { value2.PropertyValue.ToString() }));
             }
         }
     }
     if (builder.Length < 2)
     {
         return string.Empty;
     }
     return builder.Remove(builder.Length - 2, 2).ToString();
 }
Example #13
0
        public static void ExportToCsv(System.Web.HttpResponse response, DataTable exportData, string exportName)
        {
            response.Clear();
            byte[] BOM = { 0xEF, 0xBB, 0xBF }; // UTF-8 BOM karakterleri
            response.BinaryWrite(BOM);
            StringBuilder sb = new StringBuilder();
            foreach (DataColumn dc in exportData.Columns)
            {
                sb.Append((char)(34) + dc.ColumnName + (char)(34));
                sb.Append(";");
            }
            sb = sb.Remove(sb.Length - 1, 1);
            sb.AppendLine();
            foreach (DataRow dr in exportData.Rows)
            {

                for (int i = 0; i < exportData.Columns.Count; i++)
                {
                    sb.Append(dr[i].ToString().Replace(';', ',').Replace('\n', ' ').Replace('\t', ' ').Replace('\r', ' '));
                    sb.Append(";");
                }
                sb = sb.Remove(sb.Length - 1, 1);
                sb.AppendLine();
            }
            response.ContentType = "text/csv";
            response.AppendHeader("Content-Disposition", "attachment; filename=" + exportName + ".csv");
            response.Write(sb.ToString());
            response.End();
        }
        public static string ReadLine(this Stream ns)
        {
            var builder = new StringBuilder();

            byte cur = 0;
            byte prev = 0;

            while (true)
            {
                if (cur == 10)
                {
                    if (prev == 13)
                    {
                        // Remove /r/n
                        builder.Remove(builder.Length - 2, 2);
                    }
                    else
                    {
                        // Remove /n
                        builder.Remove(builder.Length - 1, 1);
                    }
                    break;
                }

                prev = cur;
                cur = (byte)ns.ReadByte();

                builder.Append((char)cur);
            }

            return builder.ToString();
        }
Example #15
0
 /// <summary>  
 /// dataTable中的全部记录转换成Json格式  
 /// </summary>  
 /// <param name="dt"></param>  
 /// <returns></returns>  
 // public static string DataTable2Json(DataTable dt,)
 //{
 //    return DataTable2JsonAfterRow(dt, 0,row);
 // }
 /// <summary>
 /// 
 /// 
 /// </summary>
 /// <param name="dt"></param>
 /// <param name="after">起行+1</param>
 /// <returns></returns>
 public static string DataTable2JsonAfterRow(DataTable dt, int after ,int row,int total)
 {
     StringBuilder jsonBuilder = new StringBuilder();
       if (dt.Rows.Count == 0)
       {
       jsonBuilder.Append("{\"total\":" + total.ToString());
       jsonBuilder.Append(",\"rows\":[]}");
       return jsonBuilder.ToString();
       }
       jsonBuilder.Append("{\"total\":"+total.ToString());
       jsonBuilder.Append(dt.TableName);
       jsonBuilder.Append(",\"rows\":[");
       for (int i = after; i < dt.Rows.Count; i++)
       {
       jsonBuilder.Append("{");
       for (int j = 0; j < dt.Columns.Count; j++)
       {
       jsonBuilder.Append("\"");
       jsonBuilder.Append(dt.Columns[j].ColumnName);
       jsonBuilder.Append("\":\"");
       jsonBuilder.Append(dt.Rows[i][j].ToString());
       jsonBuilder.Append("\",");
       }
       jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
       jsonBuilder.Append("},");
       }
       jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
       jsonBuilder.Append("]");
       jsonBuilder.Append("}");
       return jsonBuilder.ToString();
 }
Example #16
0
        /// <summary>
        /// datatable 转化为 json
        /// </summary>
        /// <param name="table"></param>
        /// <param name="columnsToParse"></param>
        /// <returns></returns>
        public static string DataTableToJson(DataTable table, params string[] columnsToParse)
        {
            if (table == null || table.Rows.Count == 0)
                return "{\"total\":0,\"rows\":[]}";

            StringBuilder sb = new StringBuilder();
            sb.Append("{\"total\":").Append(table.Rows.Count).Append(",");
            sb.Append("\"rows\":[");

            foreach (DataRow row in table.Rows)
            {
                sb.Append("{");

                foreach (string column in columnsToParse)
                {
                    sb.Append("\"").Append(column).Append("\":").Append("\"").Append(row[column].ToString().Trim()).Append("\",");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("},");
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append("]}");

            return sb.ToString();
        }
Example #17
0
        private void _run()
        {
            _log.Info("sina level1 行情接收器开始运行");
            bool isSent = false;
            if (aliases.Count != 0)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < aliases.Count; i++)
                {
                    isSent = false;
                    sb.Append(aliases[i]);
                    sb.Append(",");

                    if (i % n == (n - 1))
                    {
                        sb.Remove(sb.Length - 1, 1);
                        t_ReqSymbols.Add(sb.ToString());
                        sb.Clear();
                        isSent = true;
                    }
                }
                if (!isSent)
                {
                    sb.Remove(sb.Length - 1, 1);
                    t_ReqSymbols.Add(sb.ToString());
                }
            }

            foreach (string item in t_ReqSymbols)
            {
                _sendRequest(item);
            }
        }
        public static string DataTableToJson(DataTable table, params string[] columnsToParse)
        {
            if (table == null || table.Rows.Count == 0)
                return "{\"total\":0,\"rows\":[]}";

            StringBuilder sb = new StringBuilder();
            sb.Append("{\"total\":").Append(table.Rows.Count).Append(",");
            sb.Append("\"rows\":[");

            foreach (DataRow row in table.Rows)
            {
                sb.Append("{");

                if (columnsToParse.Count() == 0)
                {
                    columnsToParse = ParserHelper.GetColumnName(table);
                }
                foreach (string column in columnsToParse)
                {
                    string m_ColumnValue = GetConfigInfo.FormatDecimalPlaces(row[column], table.Columns[column].DataType);  //增加保留小数点功能
                    sb.Append("\"").Append(column).Append("\":").Append("\"").Append(m_ColumnValue.Trim()).Append("\",");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("},");
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append("]}");

            return sb.ToString();
        }
        public void Insert(string Table, List<string> ColumnNames, List<Object> Values)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("INSERT INTO ");
            sb.Append(Table);
            sb.Append(" (");
            foreach (string column in ColumnNames)
            {
                sb.Append(column);
                sb.Append(",");
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append(") VALUES (");

            foreach (object value in Values)
            {
                if (value.GetType() == typeof(double) || value.GetType() == typeof(int))
                {
                    sb.Append(value.ToString().Replace(',', '.') + ",");
                }
                else
                {
                    sb.Append("'" + value + "',");

                }
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append(")");
            Execute(sb.ToString());
        }
Example #20
0
        static void Main(string[] args)
        {
            string text = Console.ReadLine();

            int start = text.IndexOf("<upcase>");
            int end = text.IndexOf("</upcase>") + 9;

            while(start != -1 && end != -1)
            {
                StringBuilder sb = new StringBuilder(text);
                for(int i= start; i<end; i++)
                {
                    if(sb[i] >= 'a' && sb[i]<='z')
                    {
                        sb[i] -= (char)32;
                    }
                }

                sb = sb.Remove(end - 9, 9);
                sb = sb.Remove(start, 8);
                text = sb.ToString();
                start = text.IndexOf("<upcase>");
                end = text.IndexOf("</upcase>") + 9;
            }

            Console.WriteLine(text);
        }
Example #21
0
        public static string RandomPassword(int length)
        {
            var sb = new StringBuilder();

            sb.Append("1");
            sb.Append("A");
            sb.Append("a");
            sb.Append("!");

            for (var i = 0; i < length; i++)
            {
                sb.Append(
                    Convert.ToChar(Convert.ToInt32(Math.Floor((26 * DataHelper.Random.NextDouble()) + 65))));
            }

            if (sb.Length > 10)
            {
                sb.Append(DateTime.Now.ToString("hhMMssffff"));
                sb.Remove(0, 10);
            }
            else if (sb.Length > 6)
            {
                sb.Append(DateTime.Now.ToString("hhMMss"));
                sb.Remove(0, 6);
            }

            return sb.ToString();
        }
        public byte[] ToBytes()
        {
            int totalLen = 0;
            byte[] bytes = new byte[TOTAL_WIDTH];

            StringBuilder sb = new StringBuilder();
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthFigure(QUERY_TYPE, 1));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthString(ACCOUNT_DATE, 8));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthString(NOTICE_NO, 20));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthFigure(NOTICE_TYPE, 1));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthFigure(BUSINESS_TYPE, 1));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthString(RESERVE, 256));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);

            return bytes;
        }
        public byte[] ToBytes()
        {
            int totalLen = 0;
            byte[] bytes = new byte[TOTAL_WIDTH];

            StringBuilder sb = new StringBuilder();
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthString(SignType, 1));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthString(ORG_NO, 6));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthString(STF_NO, 7));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            
            if (PIN_BLK == null)
            {
                PIN_BLK = new byte[24];
            }
            Array.Copy(PIN_BLK, 0, bytes, totalLen, PIN_BLK.Length);
            totalLen += 24;
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthString(CARD_NO, 20));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            sb = sb.Append(CommonDataHelper.FillSpecifyWidthString(SystemDate, 8));
            CommonDataHelper.ResetByteBuffer(sb, ref bytes, ref totalLen, true);
            sb.Remove(0, sb.Length);
            return bytes;
        }
Example #24
0
        protected string NormalizePhoneNumber(string phoneNumber)
        {
            StringBuilder normalizedNumber = new StringBuilder();
            foreach (char symbol in phoneNumber)
            {
                if (char.IsDigit(symbol) || (symbol == '+'))
                {
                    normalizedNumber.Append(symbol);
                }
            }

            if (normalizedNumber.Length >= 2 && normalizedNumber[0] == '0' && normalizedNumber[1] == '0')
            {
                normalizedNumber.Remove(0, 1);
                normalizedNumber[0] = '+';
            }

            while (normalizedNumber.Length > 0 && normalizedNumber[0] == '0')
            {
                normalizedNumber.Remove(0, 1);
            }

            if (normalizedNumber.Length > 0 && normalizedNumber[0] != '+')
            {
                normalizedNumber.Insert(0, DefaultCountryCode);
            }

            return normalizedNumber.ToString();
        }
Example #25
0
		public static string ToCharacterSeparatedValues(this DataTable table, string delimiter, bool includeHeader)
		{
			var result = new StringBuilder();

			if (includeHeader)
			{
				foreach (DataColumn column in table.Columns)
				{
					result.Append(column.ColumnName);
					result.Append(delimiter);
				}

				result.Remove(result.Length, 0);
				result.AppendLine();
			}

			foreach (DataRow row in table.Rows)
			{
				for (var x = 0; x < table.Columns.Count; x++)
				{
					if (x != 0)
						result.Append(delimiter);

					result.Append(row[table.Columns[x]]);
				}

				result.AppendLine();
			}

			result.Remove(result.Length, 0);
			result.AppendLine();

			return result.ToString();
		}
Example #26
0
        /// <summary>  
        /// dataTable转换成Json格式  
        /// </summary>  
        /// <param name="dt"></param>  
        /// <returns></returns>  
        public static string DataTable2Json(List<Area> ds)
        {
            StringBuilder jsonBuilder = new StringBuilder();
            if (ds != null && ds.Count > 0)
            {
                jsonBuilder.Append("[");
                for (int i = 0; i < ds.Count; i++)
                {
                    jsonBuilder.Append("{");
                    jsonBuilder.Append("\"");
                    jsonBuilder.Append("AreaID");
                    jsonBuilder.Append("\":\"");
                    jsonBuilder.Append(ds[i].AreaID);
                    jsonBuilder.Append("\",");
                    jsonBuilder.Append("\"");
                    jsonBuilder.Append("AreaName");
                    jsonBuilder.Append("\":\"");
                    jsonBuilder.Append(ds[i].AreaName);
                    jsonBuilder.Append("\",");

                    jsonBuilder.Append("\"");
                    jsonBuilder.Append("FaAreaID");
                    jsonBuilder.Append("\":\"");
                    jsonBuilder.Append(ds[i].FaAreaID);
                    jsonBuilder.Append("\",");

                    jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                    jsonBuilder.Append("},");
                }
                jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                jsonBuilder.Append("]");
            }
            return jsonBuilder.ToString();
        }
        public string ConvertPhoneNumber(string num)
        {
            StringBuilder sb = new StringBuilder();

            sb.Clear();
            foreach (char ch in num)
            {
                if (char.IsDigit(ch) || (ch == '+'))
                {
                    sb.Append(ch);
                }
            }

            if (sb.Length >= 2 && sb[0] == '0' && sb[1] == '0')
            {
                sb.Remove(0, 1);
                sb[0] = '+';
            }

            while (sb.Length > 0 && sb[0] == '0')
            {
                sb.Remove(0, 1);
            }

            if (sb.Length > 0 && sb[0] != '+')
            {
                sb.Insert(0, Code);
            }

            return sb.ToString();
        }
Example #28
0
        public static string FromUpcA(string value)
        {
            if (!Regex.IsMatch(value, @"^[01]\d{2}([012]0{4}\d{3}|[3-9]0{4}\d{2}|\d{4}0{4}\d|\d{5}0{4}[5-9])"))
                throw new ArgumentException("UPC A code cannot be compressed.");

            StringBuilder result = new StringBuilder(value);

            if (result[5] != '0')
                result.Remove(6, 4);
            else if (result[4] != '0')
            {
                result.Remove(5, 5);
                result.Insert(6, "4");
            }
            else if (result[3] != '2' && result[3] != '1' && result[3] != '0')
            {
                result.Remove(4, 5);
                result.Insert(6, "3");
            }
            else
            {
                result.Insert(11, result[3]);
                result.Remove(3, 5);
            }

            return result.ToString();
        }
        public string ConvertToCanonical(string number)
        {
            var canonicalNumber = new StringBuilder();

            foreach (var ch in number.Where(ch => char.IsDigit(ch) || (ch == '+')))
            {
                canonicalNumber.Append(ch);
            }

            if (canonicalNumber.Length >= 2 && canonicalNumber[0] == '0' && canonicalNumber[1] == '0')
            {
                canonicalNumber.Remove(0, 1);
                canonicalNumber[0] = '+';
            }

            while (canonicalNumber.Length > 0 && canonicalNumber[0] == '0')
            {
                canonicalNumber.Remove(0, 1);
            }

            if (canonicalNumber.Length > 0 && canonicalNumber[0] != '+')
            {
                canonicalNumber.Insert(0, this.countryCode);
            }

            return canonicalNumber.ToString();
        }
        static void Main()
        {
            StringBuilder cages = new StringBuilder();

            while (true)
            {
                string input = Console.ReadLine();
                if (input == "END")
                {
                    break;
                }
                cages.Append(input);
            }

            int cagesToTake = int.Parse((cages[0] - '0').ToString());
            
            int cagesToRemove = 1;

            while (cagesToTake < cages.Length)
            {
                cages.Remove(0, cagesToRemove);
                BigInteger sum = 0;
                BigInteger product = 1;
                
                for (int i = 0; i < cagesToTake; i++)
                {
                    sum += BigInteger.Parse((cages[i] - '0').ToString());
                    product *= BigInteger.Parse((cages[i] - '0').ToString());
                    cages.Insert(0, "*", 1);
                    cages.Remove(0, 1);
                }
                string digitsToAppend = AppendTheSumAndProduct(cages, sum, product);
               
                cages.Remove(0, cagesToTake);
                cages.Insert(0, digitsToAppend); 

                if (cagesToRemove >= cages.Length)
                {
                    break;
                }

                cagesToRemove++;

                int cagesToSum = cagesToRemove;
                cagesToTake = SumOfDigitsToAppend(digitsToAppend, cagesToRemove);
            }

            for (int i = 0; i < cages.Length; i++)
            {
                if (i != cages.Length - 1)
                {
                    Console.Write("{0} ", cages[i]);
                }
                else
                {
                    Console.WriteLine(cages[i]);
                }
                
            }
        }