public void DisplayData(object[] data) { StringBuilder sb = new StringBuilder(); sb.Append(view.uiHeaderTemplateHolder.InnerHTML.Unescape()); if (data != null) { string currentGroupByFieldValue = ""; for (int i = 0; i < data.Length; i++) { Dictionary dataItem = (Dictionary) data[i]; if (GroupByField != "") { if (currentGroupByFieldValue != (string) dataItem[GroupByField]) { currentGroupByFieldValue = (string) dataItem[GroupByField]; sb.Append("<div class='ClientSideRepeaterGroupHeader'>" + currentGroupByFieldValue + "</div>"); } } sb.Append(this.view.uiItemTemplate.Render(dataItem)); if (i + 1 < data.Length) { sb.Append(view.uiBetweenTemplateHolder.InnerHTML.Unescape()); } } } sb.Append(view.uiFooterTemplateHolder.InnerHTML.Unescape()); view.uiContent.InnerHTML = sb.ToString(); }
private static string GenerateTemplateReplacement(Type type, PropertyInfo property) { System.StringBuilder templateValue = new System.StringBuilder("{"); templateValue.Append(type.Name); templateValue.Append(":"); templateValue.Append(property.Name); templateValue.Append("}"); return(templateValue); }
public static void maybeAppend1(String value_Renamed, StringBuilder result) { if (value_Renamed != null && value_Renamed.Length > 0) { // Don't add a newline before the first value if (result.ToString().Length > 0) { result.Append('\n'); } result.Append(value_Renamed); } }
/// <summary> /// Attempts to make the specified <see cref="String"/> <paramref name="value"/> human readable. /// </summary> /// <param name="value">The <see cref="String"/> to make readable.</param> /// <param name="normalizeConditions">A bitwise combination of <see cref="ReadablilityCondition"/> used to specify how readability is determined.</param> /// <returns>A human readable <see cref="string"/>.</returns> public static string AsReadable(this string value, ReadablilityCondition normalizeConditions = ReadablilityCondition.Default) { if (value.IsNullEmptyOrWhiteSpace()) { return(value); } if (normalizeConditions == 0) { normalizeConditions = ReadablilityCondition.Default; } string workingValue = value; // Validate Whitespace Trim Conditions if (normalizeConditions.TrimStartWhitespace()) { workingValue = workingValue.TrimStart(); } if (normalizeConditions.TrimEndWhitespace()) { workingValue = workingValue.TrimEnd(); } // Validate Normalization Conditions if (!normalizeConditions.CanMakeReadable(workingValue)) { return(workingValue); } // Declarations System.StringBuilder returnValue = new System.StringBuilder(); IEnumerable <string> workingValues = workingValue.SeperateForReadability(normalizeConditions); var iterator = workingValues.GetEnumerator(); bool hasValue = iterator.MoveNext(); bool isFirst = true; while (hasValue) { returnValue.Append(isFirst, normalizeConditions.Capitalize(iterator.Current), iterator.Current); hasValue = iterator.MoveNext(); isFirst = false; if (hasValue) { returnValue.Append(TextExtensions.WhiteSpace); } } return(returnValue); }
public string Dump() { lock(this) { StringBuilder buff = new StringBuilder(); ArrayList al = rrdMap.Values; foreach (RrdEntry rrdEntry in al) { buff.Append(rrdEntry.Dump()); buff.Append("\n"); } return buff.ToString(); } }
public static string ToGEOJson(this DataTable dt, string latColumn, string lngColumn) { StringBuilder result = new StringBuilder(); StringBuilder line; foreach (DataRow r in dt.Rows) { line = new StringBuilder(); foreach (DataColumn col in dt.Columns) { if (col.ColumnName != latColumn && col.ColumnName != lngColumn) { string cValue = r[col].ToString(); line.Append(",\"" + col.ColumnName + "\":\"" + cValue.Replace("\"","\\\"") + "\""); } } result.Append( ",{\"type\":\"Feature\",\"geometry\": {\"type\":\"Point\", \"coordinates\": [" + r[lngColumn].ToString() + "," + r[latColumn].ToString() + "]},\"properties\":{" + line.ToString().Substring(1) + "}}"); } string geojson = "{\"type\": \"FeatureCollection\",\"features\": [" + result.ToString().Substring(1) + "]}"; return geojson; }
public static string ReverseString(string s) { StringBuilder sb = new StringBuilder(); for(int i = s.Length; i > 0; i--){ sb.Append(s[i-1]); } }
public override string ToString() { StringBuilder result = new StringBuilder(); result.Append("LocalCourse { Name = "); result.Append(base.ToString()); if (!string.IsNullOrEmpty(this.Lab)) { result.Append("; Lab = "); result.Append(this.Lab); } result.Append(" }"); return result.ToString(); }
protected internal override int decodeMiddle(BitArray row, int[] startRange, StringBuilder result) { int[] counters = decodeMiddleCounters; counters[0] = 0; counters[1] = 0; counters[2] = 0; counters[3] = 0; int end = row.Size; int rowOffset = startRange[1]; for (int x = 0; x < 4 && rowOffset < end; x++) { int bestMatch = decodeDigit(row, counters, rowOffset, L_PATTERNS); result.Append(Int32Extend.ToChar(CharExtend.ToInt32('0') + bestMatch)); for (int i = 0; i < counters.Length; i++) { rowOffset += counters[i]; } } int[] middleRange = findGuardPattern(row, rowOffset, true, MIDDLE_PATTERN); rowOffset = middleRange[1]; for (int x = 0; x < 4 && rowOffset < end; x++) { int bestMatch = decodeDigit(row, counters, rowOffset, L_PATTERNS); result.Append(Int32Extend.ToChar(CharExtend.ToInt32('0') + bestMatch)); for (int i = 0; i < counters.Length; i++) { rowOffset += counters[i]; } } return rowOffset; }
/// <summary> /// Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />. /// </summary> /// <param name="baseUrl"> The base URL. </param> /// <returns> A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" /> . </returns> public virtual String ToString(String baseUrl) { var sb = new StringBuilder(); foreach (var pair in _dictionary) { if (sb.Length > 0) sb.Append("&"); sb.AppendFormat("{0}={1}", pair.Key, pair.Value); } return baseUrl.IsNotNullOrEmpty() ? String.Concat(baseUrl, "?", sb.ToString()) : sb.ToString(); }
private static string GetControllerUrlFormat(this Type controllerType, string routeArea = null, string controllerName = null) { System.StringBuilder returnValue = new System.StringBuilder(); if (!routeArea.IsNullEmptyOrWhiteSpace()) { returnValue.Append("/{0}", routeArea); } if (controllerName.IsNull()) { controllerName = controllerType.GetControllerName(); } returnValue.Append("/{0}", controllerName); returnValue.Append("/{action}/{id}"); return(returnValue); }
private string DumpGraph(DirectedGraphImpl<string> gr) { StringBuilder sb = new StringBuilder(); foreach (string n in gr.Nodes) { sb.AppendFormat("({0} s:(", n); foreach (string i in gr.Successors(n)) { sb.AppendFormat("{0} ", i); } sb.Append(") p:( "); foreach (string p in gr.Predecessors(n)) { sb.AppendFormat("{0} ", p); } sb.Append(")) "); } return sb.ToString(); }
/// <summary> /// Converts an array of bytes to a hex string representation. /// </summary> /// <param name="bytes"></param> /// <returns></returns> public static string BytesToHexString(this byte[] bytes) { var builder = new StringBuilder(); foreach (byte b in bytes) { builder.Append(StringUtility.Format("{0:X}", b)); } return builder.ToString(); }
/// <summary> /// Converts the query string to an string. /// </summary> /// <param name="data"></param> /// <param name="separator"></param> /// <param name="nameValueSeparator"></param> /// <returns></returns> public string ConvertQueryHashtable(Hashtable data, string separator, string nameValueSeparator) { // QueryString StringBuilder queryString = new StringBuilder(); foreach ( DictionaryEntry de in data ) { ArrayList itemValues = (ArrayList)de.Value; string key = (string)de.Key; if ( nameValueSeparator.Length == 0 ) { //queryString.Append(key); queryString.Append(separator); queryString.Append(itemValues[0]); } else { foreach ( string s in itemValues ) { queryString.Append(key); queryString.Append(nameValueSeparator); queryString.Append(s); queryString.Append(separator); } } } return queryString.ToString(); }
/// <summary> /// Serialize the array elements as item1,item2,item3 /// </summary> public static string SerializeArrayAsString(IList list) { System.StringBuilder txt = new System.StringBuilder(); foreach (var item in list) { txt.Append("\"{0}\",", item); } if (txt.Length > 0) { txt.Remove(txt.Length - 1, 1); } return(txt.ToString()); }
private static string CalculateHash(string input, HashAlgorithm hashAlgorithm) { byte[] inputBytes; byte[] hash; using (var hashProvider = hashAlgorithm) { inputBytes = Encoding.ASCII.GetBytes(input); hash = hashProvider.ComputeHash(inputBytes); } // step 2, convert byte array to hex string var sb = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { sb.Append(hash[i].ToString("X2", CultureInfo.InvariantCulture)); } return sb.ToString(); }
public static string GenerateRandomId() { int maxSize = 36; char[] chars = new char[62]; string a; a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; chars = a.ToCharArray(); int size = maxSize; byte[] data = new byte[1]; RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider(); crypto.GetNonZeroBytes(data); size = maxSize; data = new byte[size]; crypto.GetNonZeroBytes(data); StringBuilder result = new StringBuilder(size); foreach (byte b in data) { result.Append(chars[b % (chars.Length - 1)]); } return result.ToString(); }
public override string ToString() { StringBuilder result = new StringBuilder(); result.Append("OffsiteCourse { Name = "); result.Append(base.ToString()); result.Append("; Students = "); result.Append(this.GetStudentsAsString()); if (!string.IsNullOrEmpty(this.Town)) { result.Append("; Town = "); result.Append(this.Town); } result.Append(" }"); return result.ToString(); }
/// <summary> /// Returns a combined value of strings from a String array /// </summary> /// <param name = "values">The values.</param> /// <param name = "prefix">The prefix.</param> /// <param name = "suffix">The suffix.</param> /// <param name = "quotation">The quotation (or null).</param> /// <param name = "separator">The separator.</param> /// <returns> /// A <see cref = "System.String" /> that represents this instance. /// </returns> /// <remarks> /// Contributed by blaumeister, http://www.codeplex.com/site/users/view/blaumeiser /// </remarks> public static String ToString(this String[] values, String prefix = "(", String suffix = ")", String quotation = "\"", String separator = ",") { var sb = new StringBuilder(); sb.Append(prefix); for (var i = 0; i < values.Length; ++i) { if (i > 0) sb.Append(separator); if (quotation != null) sb.Append(quotation); sb.Append(values[i]); if (quotation != null) sb.Append(quotation); } sb.Append(suffix); return sb.ToString(); }
/// <summary> /// Gets an identifier for a property based on its name, its containing object's name and/or type. This is intended to /// help the user zero in on the offending line/element in a xaml file, when we don't have access to a parser to /// report line numbers. /// </summary> /// <param name="propertyName"> The name of the property. </param> /// <param name="containingObjectName"> The name of the containing object. </param> /// <param name="containingObject"> The object which contains this property. </param> /// <returns> Returns "(containingObject's type name)containingObjectName.PropertyName". </returns> internal static string GetPropertyId(string propertyName, string containingObjectName, object containingObject) { ErrorUtilities.VerifyThrowArgumentLength(propertyName, "propertyName"); ErrorUtilities.VerifyThrowArgumentLength(containingObjectName, "containingObjectName"); ErrorUtilities.VerifyThrowArgumentNull(containingObject, "containingObject"); StringBuilder propertyId = new StringBuilder(); propertyId.Append("("); propertyId.Append(containingObject.GetType().Name); propertyId.Append(")"); if (!string.IsNullOrEmpty(containingObjectName)) { propertyId.Append(containingObjectName); } propertyId.Append("."); propertyId.Append(propertyName); return propertyId.ToString(); }
public override AnchorInfo GetAnchorInfo (bool reverse) { int ptr; int width = GetFixedWidth (); ArrayList infos = new ArrayList (); IntervalCollection segments = new IntervalCollection (); // accumulate segments ptr = 0; int count = Expressions.Count; for (int i = 0; i < count; ++ i) { Expression e; if (reverse) e = Expressions [count - i - 1]; else e = Expressions [i]; AnchorInfo info = e.GetAnchorInfo (reverse); infos.Add (info); if (info.IsPosition) return new AnchorInfo (this, ptr + info.Offset, width, info.Position); if (info.IsSubstring) segments.Add (info.GetInterval (ptr)); if (info.IsUnknownWidth) break; ptr += info.Width; } // normalize and find the longest segment segments.Normalize (); Interval longest = Interval.Empty; foreach (Interval segment in segments) { if (segment.Size > longest.Size) longest = segment; } if (longest.IsEmpty) return new AnchorInfo (this, width); // now chain the substrings that made this segment together bool ignore = false; int n_strings = 0; ptr = 0; for (int i = 0; i < infos.Count; ++i) { AnchorInfo info = (AnchorInfo) infos [i]; if (info.IsSubstring && longest.Contains (info.GetInterval (ptr))) { ignore |= info.IgnoreCase; infos [n_strings ++] = info; } if (info.IsUnknownWidth) break; ptr += info.Width; } StringBuilder sb = new StringBuilder (); for (int i = 0; i < n_strings; ++i) { AnchorInfo info; if (reverse) info = (AnchorInfo) infos [n_strings - i - 1]; else info = (AnchorInfo) infos [i]; sb.Append (info.Substring); } if (sb.Length == longest.Size) return new AnchorInfo (this, longest.low, width, sb.ToString (), ignore); // were the string segments overlapping? if (sb.Length > longest.Size) { Console.Error.WriteLine ("overlapping?"); return new AnchorInfo (this, width); } throw new SystemException ("Shouldn't happen"); }
public override String ToString() { StringBuilder result = new StringBuilder(); for (int degree = Degree; degree >= 0; degree--) { int coefficient = getCoefficient(degree); if (coefficient != 0) { if (coefficient < 0) { result.Append(" - "); coefficient = - coefficient; } else { if (result.ToString().Length > 0) { result.Append(" + "); } } if (degree == 0 || coefficient != 1) { int alphaPower = field.log(coefficient); if (alphaPower == 0) { result.Append('1'); } else if (alphaPower == 1) { result.Append('a'); } else { result.Append("a^"); result.Append(alphaPower); } } if (degree != 0) { if (degree == 1) { result.Append('x'); } else { result.Append("x^"); result.Append(degree); } } } } return result.ToString(); }
public static string ToJsonTable(this DataTable dt) { StringBuilder sb = new StringBuilder(); foreach (DataColumn column in dt.Columns) { sb.Append(",'" + column.ColumnName + "'"); } List<object[]> data = new List<object[]>(); foreach(DataRow row in dt.Rows) { data.Add(row.ItemArray); } System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); string json = "{\"columns\":[" + sb.ToString().Substring(1) + "],\"data\":" + serializer.Serialize(data) + "}"; return json; }
//------------------------------------------------------ // // OBJECT METHOD OVERRIDES // //------------------------------------------------------ public String ToString() { #if _DEBUG StringBuilder sb = new StringBuilder(); sb.Append("UIPermission("); if (IsUnrestricted()) { sb.Append("Unrestricted"); } else { sb.Append(m_stateNameTableWindow[m_windowFlag]); sb.Append(", "); sb.Append(m_stateNameTableClipboard[m_clipboardFlag]); } sb.Append(")"); return sb.ToString(); #else return super.ToString(); #endif }
public static String ExpandEnvironmentVariables(String name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } Contract.EndContractBlock(); if (name.Length == 0) { return(name); } int currentSize = 100; StringBuilder blob = new StringBuilder(currentSize); // A somewhat reasonable default size #if PLATFORM_UNIX // Win32Native.ExpandEnvironmentStrings isn't available 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)); #else int size; blob.Length = 0; size = Win32Native.ExpandEnvironmentStrings(name, blob, currentSize); if (size == 0) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } while (size > currentSize) { currentSize = size; blob.Capacity = currentSize; blob.Length = 0; size = Win32Native.ExpandEnvironmentStrings(name, blob, currentSize); if (size == 0) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } #endif // PLATFORM_UNIX return(blob.ToString()); }
public override String ToString() { StringBuilder result = new StringBuilder(); for (int i = 0; i < size; i++) { if ((i & 0x07) == 0) { result.Append(' '); } result.Append(get_Renamed(i)?'X':'.'); } return result.ToString(); }
public override AnchorInfo GetAnchorInfo (bool reverse) { int width = GetFixedWidth (); if (Minimum == 0) return new AnchorInfo (this, width); AnchorInfo info = Expression.GetAnchorInfo (reverse); if (info.IsPosition) return new AnchorInfo (this, info.Offset, width, info.Position); if (info.IsSubstring) { if (info.IsComplete) { // Minimum > 0 string str = info.Substring; StringBuilder sb = new StringBuilder (str); for (int i = 1; i < Minimum; ++ i) sb.Append (str); return new AnchorInfo (this, 0, width, sb.ToString (), info.IgnoreCase); } return new AnchorInfo (this, info.Offset, width, info.Substring, info.IgnoreCase); } return new AnchorInfo (this, width); }
internal string RTLReplace (Regex regex, string input, MatchEvaluator evaluator, int count, int startat) { Match m = Scan (regex, input, startat, input.Length); if (!m.Success) return input; int ptr = startat; int counter = count; #if NET_2_1 var pieces = new System.Collections.Generic.List<string> (); #else StringCollection pieces = new StringCollection (); #endif pieces.Add (input.Substring (ptr)); do { if (count != -1) if (counter-- <= 0) break; if (m.Index + m.Length > ptr) throw new SystemException ("how"); pieces.Add (input.Substring (m.Index + m.Length, ptr - m.Index - m.Length)); pieces.Add (evaluator (m)); ptr = m.Index; m = m.NextMatch (); } while (m.Success); StringBuilder result = new StringBuilder (); result.Append (input, 0, ptr); for (int i = pieces.Count; i > 0; ) result.Append (pieces [--i]); pieces.Clear (); return result.ToString (); }
internal string LTRReplace (Regex regex, string input, MatchAppendEvaluator evaluator, int count, int startat, bool needs_groups_or_captures) { this.needs_groups_or_captures = needs_groups_or_captures; Match m = Scan (regex, input, startat, input.Length); if (!m.Success) return input; StringBuilder result = new StringBuilder (input.Length); int ptr = startat; int counter = count; result.Append (input, 0, ptr); do { if (count != -1) if (counter-- <= 0) break; if (m.Index < ptr) throw new SystemException ("how"); result.Append (input, ptr, m.Index - ptr); evaluator (m, result); ptr = m.Index + m.Length; m = m.NextMatch (); } while (m.Success); result.Append (input, ptr, input.Length - ptr); return result.ToString (); }
public void Switch(CodeLabel[] jumpTable) { Label[] labels = new Label[jumpTable.Length]; #if DEBUG_COMPILE StringBuilder sb = new StringBuilder(OpCodes.Switch.ToString()); #endif for (int i = 0; i < labels.Length; i++) { labels[i] = jumpTable[i].Value; #if DEBUG_COMPILE sb.Append("; ").Append(i).Append("=>").Append(jumpTable[i].Index); #endif } il.Emit(OpCodes.Switch, labels); #if DEBUG_COMPILE Helpers.DebugWriteLine(sb.ToString()); #endif }
private String GetExceptionMethodString() { MethodBase methBase = GetTargetSiteInternal(); if (methBase == null) { return(null); } if (methBase is System.Reflection.Emit.DynamicMethod.RTDynamicMethod) { // DynamicMethods cannot be serialized return(null); } // Note that the newline separator is only a separator, chosen such that // it won't (generally) occur in a method name. This string is used // only for serialization of the Exception Method. char separator = '\n'; StringBuilder result = new StringBuilder(); if (methBase is ConstructorInfo) { RuntimeConstructorInfo rci = (RuntimeConstructorInfo)methBase; Type t = rci.ReflectedType; result.Append((int)MemberTypes.Constructor); result.Append(separator); result.Append(rci.Name); if (t != null) { result.Append(separator); result.Append(t.Assembly.FullName); result.Append(separator); result.Append(t.FullName); } result.Append(separator); result.Append(rci.ToString()); } else { Debug.Assert(methBase is MethodInfo, "[Exception.GetExceptionMethodString]methBase is MethodInfo"); RuntimeMethodInfo rmi = (RuntimeMethodInfo)methBase; Type t = rmi.DeclaringType; result.Append((int)MemberTypes.Method); result.Append(separator); result.Append(rmi.Name); result.Append(separator); result.Append(rmi.Module.Assembly.FullName); result.Append(separator); if (t != null) { result.Append(t.FullName); result.Append(separator); } result.Append(rmi.ToString()); } return(result.ToString()); }
/// <summary> /// Returns a <see cref="System.String"/> that represents this instance. /// </summary> /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> public override string ToString() { return base.ToString(); #if false StringBuilder sb = new StringBuilder(30); // The size of the operand. switch (RequestedSize) { case DataSize.Bit8: sb.Append("byte "); break; case DataSize.Bit16: sb.Append("word "); break; case DataSize.Bit32: sb.Append("dword "); break; case DataSize.Bit64: sb.Append("qword "); break; case DataSize.Bit128: sb.Append("oword "); break; case DataSize.None: default: break; } sb.Append("["); // The width of the displacement value. switch (displacementSize) { case DataSize.Bit8: sb.Append("byte "); break; case DataSize.Bit16: sb.Append("word "); break; case DataSize.Bit32: sb.Append("dword "); break; case DataSize.Bit64: sb.Append("qword "); break; case DataSize.Bit128: sb.Append("oword "); break; case DataSize.None: default: break; } if (baseRegister != X86Register.None) sb.Append(baseRegister.GetName()); if (indexRegister != X86Register.None && scale > 0) { if (baseRegister != X86Register.None) sb.Append("+"); sb.Append(indexRegister.GetName()); if (scale > 1) { sb.Append("*"); sb.Append(scale); } } if (displacement != null) { if (baseRegister != X86Register.None || (indexRegister != X86Register.None && scale > 0)) sb.Append("+"); sb.Append(displacement.ToString()); } sb.Append("]"); return sb.ToString(); #endif }
public static void ShowMarketplace (PlayerIndex player) { AssertInitialised(); string bundleName = NSBundle.MainBundle.InfoDictionary[new NSString("CFBundleName")].ToString(); StringBuilder output = new StringBuilder(); foreach (char c in bundleName) { // Ampersand gets converted to "and"!! if (c == '&') output.Append("and"); // All alphanumeric characters are added if (char.IsLetterOrDigit(c)) output.Append(c); } NSUrl url = new NSUrl("itms-apps://itunes.com/app/" + output.ToString()); if (!UIApplication.SharedApplication.OpenUrl(url)) { // Error } }
protected internal static String unescapeBackslash(String escaped) { if (escaped != null) { int backslash = escaped.IndexOf('\\'); if (backslash >= 0) { int max = escaped.Length; StringBuilder unescaped = new StringBuilder(); unescaped.Append(escaped.Substr(0, backslash)); bool nextIsEscaped = false; for (int i = backslash; i < max; i++) { char c = escaped.CharAt(i); if (nextIsEscaped || c != '\\') { unescaped.Append(c); nextIsEscaped = false; } else { nextIsEscaped = true; } } return unescaped.ToString(); } } return escaped; }
public StringBuilder Insert(int index, string value, int count) { if (count < 0) { throw new ArgumentOutOfRangeException(); } if (count == 0 || string.IsNullOrEmpty(value)) { return this; } StringBuilder toInsert = new StringBuilder(value.Length * count); for (; count > 0; count--) { toInsert.Append(value); } return this.Insert(index, toInsert.ToString()); }
private static String urlDecode(String escaped) { // No we can't use java.net.URLDecoder here. JavaME doesn't have it. if (escaped == null) { return null; } char[] escapedArray = StringExtend.ToCharArray(escaped); int first = findFirstEscape(escapedArray); if (first < 0) { return escaped; } int max = escapedArray.Length; // final length is at most 2 less than original due to at least 1 unescaping StringBuilder unescaped = new StringBuilder(); // Can append everything up to first escape character unescaped.Append(escaped.Substr(0, first)); for (int i = first; i < max; i++) { char c = escapedArray[i]; if (c == '+') { // + is translated directly into a space unescaped.Append(' '); } else if (c == '%') { // Are there even two more chars? if not we will just copy the escaped sequence and be done if (i >= max - 2) { unescaped.Append('%'); // append that % and move on } else { int firstDigitValue = parseHexDigit(escapedArray[++i]); int secondDigitValue = parseHexDigit(escapedArray[++i]); if (firstDigitValue < 0 || secondDigitValue < 0) { // bad digit, just move on unescaped.Append('%'); unescaped.Append(escapedArray[i - 1]); unescaped.Append(escapedArray[i]); } unescaped.Append((char) ((firstDigitValue << 4) + secondDigitValue)); } } else { unescaped.Append(c); } } return unescaped.ToString(); }