本文整理汇总了C#中System.String.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# String.Insert方法的具体用法?C# String.Insert怎么用?C# String.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.Insert方法的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
示例2: getDateTime
/// <summary>
/// Get DateTime from string
/// </summary>
/// <param name="dateTimeString">String containing DateTime</param>
/// <returns>Object of DateTime</returns>
internal static DateTime getDateTime(String dateTimeString)
{
DateTime dateTime;
dateTimeString = dateTimeString.Insert(10, " ");
dateTime = Convert.ToDateTime(dateTimeString);
return dateTime;
}
示例3: capitalize
private String capitalize(String text)
{
String first = text[0].ToString();
text = text.Remove(0, 1);
first = first.ToUpper();
text = text.Insert(0, first);
return text;
}
示例4: swapSecondAndThirdDigits
private static String swapSecondAndThirdDigits(String str)
{
String tmp = str[1].ToString();
str = str.Remove(1, 1);
str = str.Insert(2, tmp);
return str;
}
示例5: CheckForImplicitMultiplication
private static string CheckForImplicitMultiplication(String expression)
{
for (var i = 1; i < expression.Count() - 1; i++)
if ((expression[i] == ')' && Char.IsNumber(expression[i + 1])) ||
(expression[i] == '(' && Char.IsNumber(expression[i - 1])))
expression = expression.Insert(i + 1, "*");
return expression;
}
示例6: ReplaceDocumentIDInMetadata
/// <summary>
/// Replace the document id in the given metadata
/// </summary>
/// <param name="metadata">A metadata string</param>
/// <param name="documentid">The document id which should be inserted</param>
/// <returns>Returns a metadata string with the new document id</returns>
public static String ReplaceDocumentIDInMetadata(String metadata, int documentid)
{
int startIndex = metadata.IndexOf("docid") + 5;
int endIndex = metadata.IndexOf("|");
metadata = metadata.Remove(startIndex, endIndex - startIndex);
metadata = metadata.Insert(startIndex, " " + documentid.ToString());
return metadata;
}
示例7: Read
/// <summary>
/// Reads matrix and branches (if exists) from specified file.
/// </summary>
/// <param name="filePath">File path.</param>
/// <param name="networkSize">The size of the network (matrix, which represents the network).</param>
/// <param name="matrixType">The type of given matrix (content of the specified file)</param>
/// <returns>Matrix and branches (if exists).</returns>
/// <throws>CoreException, MatrixFormatException.</throws>
public static MatrixInfoToRead Read(String filePath, int networkSize, AdjacencyMatrixType matrixType)
{
MatrixInfoToRead result = new MatrixInfoToRead();
result.Matrix = MatrixReader(filePath, networkSize, matrixType);
result.Branches = BranchesReader(filePath.Insert(filePath.Length - 4, "_branches"));
return result;
}
示例8: CleanString
public void CleanString(String s)
{
if (s.Length != 0) {
s.Replace(" ", "");
while (s.Length < 8) {
s.Insert(0, "0");
}
}
}
示例9: Tag
public static string Tag(String rootRelativePath)
{
if (HttpRuntime.Cache[rootRelativePath] == null)
{
string absolute = HostingEnvironment.MapPath("~" + rootRelativePath);
DateTime date = File.GetLastWriteTime(absolute);
int index = rootRelativePath.LastIndexOf('/');
string result = rootRelativePath.Insert(index, "/v-" + date.Ticks);
HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute));
}
return HttpRuntime.Cache[rootRelativePath] as string;
}
示例10: _ConvertToStringFilePath
public static String _ConvertToStringFilePath(String _filePath)
{
char searchChar = '\\';
Int32 index = new Int32();
while((index = _filePath.IndexOf(searchChar, index)) != -1)
{
if ((index + 1) < _filePath.Length && _filePath[index + 1] != searchChar)
{
_filePath.Insert(index, searchChar.ToString());
index++;
}
index++;
}
return _filePath;
}
示例11: ParseANSI
private string ParseANSI(String s)
{
//統一用\n換行
s = s.Replace( "\r\n", "\n" ).Replace( "\r", "\n" );
//htmlspecialchars()
s = s.Replace( "&", "&" ).Replace( "<", "<" ).Replace( ">", ">" );
/* TODO: 目前取時間有誤 */
//解析作者、看板、標題、時間等資訊
//s = Regex.Replace( s, "^(?:作者|發信人):\\s([^\\s]*)\\s\\(([^\\)]*)\\)\\s(站內|看板):\\s([^(\\r|\\n)]*)(?:\\r\\n|\\r|\\n)(?:標題|標 題):\\s([^(\\r|\\n)]*)(?:\\r\\n|\\r|\\n)(?:時間|發信站):\\s([^(\\r|\\n)]*)?\\s?\\(?(d{4}\\/\\d{2}\\/\\d{2}\\s(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\\s\\d{2}:\\d{2}:\\d{2})\\)?"
s = Regex.Replace( s, "^(?:作者|發信人):\\s([^\\s]*)\\s\\(([^\\)]*)\\)\\s(站內|看板):\\s([^\\n]*)\\n(?:標題|標 題):\\s([^\\n]*)\\n(?:時間|發信站):\\s([^\\n]*)"
, "<div class=\"entry-meta\"><div class=\"author vcard\"><span class=\"label\">作者</span> <span class=\"nickname\">$1</span> (<span class=\"fn n\">$2</span>)</div><div class=\"board\"><span class=\"label\">$3</span> <span class=\"board-title\">$4</span></div><div class=\"entry-title\"><span class=\"label\">標題</span> <h1>$5</h1></div><div class=\"entry-date\"><span class=\"label\">時間</span> <span class=\"published\">$6</span></div></div>"
, RegexOptions.Compiled );
//找地方插入 <pre class="entry-content">
int content_pos = s.Contains( "</div>\n" ) ? s.LastIndexOf( "</div>\n" ) + 7 : 0;
s = s.Insert( content_pos, "<pre class=\"entry-content\">" );
//解析「※」開頭文字
s = Regex.Replace( s, "^※.*$", "<span class=\"quote\">$&</span>", RegexOptions.Multiline );
/* TODO: 要作巢狀引文嗎? */
//解析引文
s = Regex.Replace( s, "^(?:>|:)\\s.*$", "<blockquote>$&</blockquote>", RegexOptions.Multiline )
.Replace( "</blockquote>\n<blockquote>", "\n" ); //移除多餘標注
//取出控制碼,執行ANSI轉HTML
s = Regex.Replace( s, "\u001B\\[([0-7;]*)m", new MatchEvaluator( this._ParseANSI ), RegexOptions.Compiled );
//如果前面有未關閉的標籤,先關閉之
s += opened == true ? "</span>" : "";
//處理超連結
s = Regex.Replace( s, "(https?|ftps?|telnet|mms|rtsp|ircs?|ed2k|ssh|svn|svn+ssh)://[0-9a-zA-Z/?|@:%&#~=$-_.+!*'()\\,]+", "<a href=\"$&\">$&</a>", RegexOptions.Compiled );
s = Regex.Replace( s, "[0-9a-zA-Z.!#$%*/?|^{}`~&'+-=_][email protected][0-9a-zA-Z-.]+", "<a href=\"mailto:$&\">$&</a>", RegexOptions.Compiled );
s += "</pre>";
return s;
}
示例12: parseDate
/// <summary>
/// Parse a rfc 2822 date and time specification. rfc 2822 section 3.3
/// </summary>
/// <param name="date">rfc 2822 date-time</param>
/// <returns>A <see cref="System.DateTime" /> from the parsed header body</returns>
public static DateTime parseDate( String date )
{
if ( date==null || date.Equals(String.Empty) )
return DateTime.MinValue;
DateTime msgDateTime;
date = SharpMimeTools.SharpMimeTools.uncommentString (date);
msgDateTime = new DateTime (0);
try {
// TODO: Complete the list
date = date.Replace("UT", "+0000");
date = date.Replace("GMT", "+0000");
date = date.Replace("EDT", "-0400");
date = date.Replace("EST", "-0500");
date = date.Replace("CDT", "-0500");
date = date.Replace("MDT", "-0600");
date = date.Replace("MST", "-0600");
date = date.Replace("EST", "-0700");
date = date.Replace("PDT", "-0700");
date = date.Replace("PST", "-0800");
date = date.Replace("AM", String.Empty);
date = date.Replace("PM", String.Empty);
int rpos = date.LastIndexOfAny(new Char[]{' ', '\t'});
if (rpos>0 && rpos != date.Length - 6)
date = date.Substring(0, rpos + 1) + "-0000";
date = date.Insert(date.Length-2, ":");
msgDateTime = DateTime.ParseExact(date,
_date_formats,
CultureInfo.CreateSpecificCulture("en-us"),
DateTimeStyles.AllowInnerWhite);
#if LOG
} catch ( System.Exception e ) {
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("Error parsing date: [", date, "]"), e);
#else
} catch ( Exception ) {
#endif
msgDateTime = new DateTime (0);
}
return msgDateTime;
}
示例13: parseLine
private void parseLine(String parsedLine)
{
if (modeCountOnly)
{
if (parsedLine.StartsWith(" ") && parsedLine.Length != 2) numTests++;
}
else
{
if (TEST_START.IsMatch(parsedLine))
{
currentTestName = TEST_START.Match(parsedLine).Groups[1].Value;
potentialErrorText = "";
}
else if (currentTestName != null)
{
if (parsedLine.StartsWith("[ OK ] " + currentTestName))
{
notifyTestComplete(currentTestName, null);
currentTestName = null;
}
else if (parsedLine.StartsWith("[ FAILED ] " + currentTestName))
{
notifyTestComplete(currentTestName, potentialErrorText);
currentTestName = null;
}
else if (!parsedLine.StartsWith("["))
{
int errorStringIndex = parsedLine.IndexOf(": error:");
if (errorStringIndex != -1)
{
int errorStringStartsAt = errorStringIndex + 8;
parsedLine = parsedLine.Remove(errorStringStartsAt, 1);
parsedLine = parsedLine.Insert(errorStringStartsAt, "\r\n");
}
potentialErrorText += parsedLine + "\r\n";
}
}
}
}
示例14: RSA_SendString
public void RSA_SendString(String _TxData)
{
//Pad the string length with whitespace to make a size evenly divisible into blocks:
int toAdd = _TxData.Length % BlockSize;
for(int i = 0; i < toAdd; i++)
{
_TxData = _TxData.Insert(_TxData.Length, " ");
}
//Figure out how many blocks need to be transmitted:
int numBlocks = _TxData.Length / BlockSize;
//Start the message transmit:
m_CommStack.StartEncryptedMessage(numBlocks);
//Encrypt the blocks and dump into the output stream:
for (int i = 0; i < numBlocks; i++)
{
char[] temp = _TxData.ToCharArray(i * BlockSize, BlockSize);
byte[] bytes = new byte[BlockSize];
int j = 0;
foreach (char c in temp)
{
bytes[j++] = Convert.ToByte(c);
}
byte[] encrypted = m_RSAEncryptSvc.Encrypt(bytes, false);
//Transmit the encrypted block.
m_CommStack.TransmitEncryptedBlock(BlockSize, encrypted);
}
//Transmit end encrypted message
m_CommStack.EndEncryptedMessage();
}
示例15: AddMarkOfTheWeb
public static string AddMarkOfTheWeb(String html, String webUrl)
{
Regex docType = new Regex("<!DOCTYPE[^>]*>");
Regex savedFrom = new Regex("<!-- saved from url.* -->");
//remove the existing savedFrom
Match m = savedFrom.Match(html);
if (m.Success)
{
html = html.Remove(m.Index, m.Length);
}
int markOffset = 0;
m = docType.Match(html);
if (m.Success && html.Substring(0, m.Index).Trim() == String.Empty)
{
markOffset = m.Index + m.Length;
}
String markOfTheWeb = UrlHelper.GetSavedFromString(webUrl);
html = html.Insert(markOffset, markOfTheWeb);
if (markOffset == 0)
{
//prepend a default docType declaration (fixes bug 487389)
html = DEFAULT_MOTW_DOCTYPE + "\r\n" + html;
}
return html;
}