本文整理汇总了C#中String.ToCharArray方法的典型用法代码示例。如果您正苦于以下问题:C# String.ToCharArray方法的具体用法?C# String.ToCharArray怎么用?C# String.ToCharArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.ToCharArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WritePascalString
public void WritePascalString(String s)
{
Char[] c = s.Length > 255 ? s.Substring(0, 255).ToCharArray() : s.ToCharArray();
base.Write((Byte)c.Length);
base.Write(c);
Int32 realLength = c.Length + 1;
if ((realLength % 2) == 0) return;
for (Int32 i = 0; i < (2 - (realLength % 2)); i++) base.Write((Byte)0);
if (AutoFlush) Flush();
}
示例2: writeRaw_14
//[Variation(id = 14, Desc = "Index = Count = 0", Pri = 1)]
public int writeRaw_14()
{
string lang = new String('a', 1);
char[] buffer = lang.ToCharArray();
using (XmlWriter w = CreateWriter())
{
w.WriteStartElement("root");
w.WriteStartAttribute("xml", "lang", null);
w.WriteRaw(buffer, 0, 0);
w.WriteEndElement();
}
return CompareReader("<root xml:lang=\"\" />") ? TEST_PASS : TEST_FAIL;
}
示例3: ParseHttpDate
ParseHttpDate(
String DateString,
out DateTime dtOut
) {
int index = 0;
int i = 0, iLastLettered = -1;
bool fIsANSIDateFormat = false;
int [] rgdwDateParseResults = new int[MAX_FIELD_DATE_ENTRIES];
bool fRet = true;
char [] lpInputBuffer = DateString.ToCharArray();
dtOut = new DateTime();
//
// Date Parsing v2 (1 more to go), and here is how it works...
// We take a date string and churn through it once, converting
// integers to integers, Month,Day, and GMT strings into integers,
// and all is then placed IN order in a temp array.
//
// At the completetion of the parse stage, we simple look at
// the data, and then map the results into the correct
// places in the SYSTIME structure. Simple, No allocations, and
// No dirting the data.
//
// The end of the function does something munging and pretting
// up of the results to handle the year 2000, and TZ offsets
// Note: do we need to fully handle TZs anymore?
//
while (index < DateString.Length && i < MAX_FIELD_DATE_ENTRIES) {
if (lpInputBuffer[index] >= '0' && lpInputBuffer[index] <= '9') {
//
// we have a numerical entry, scan through it and convent to DWORD
//
rgdwDateParseResults[i] = 0;
do {
rgdwDateParseResults[i] *= BASE_DEC;
rgdwDateParseResults[i] += (lpInputBuffer[index] - '0');
index++;
} while (index < DateString.Length &&
lpInputBuffer[index] >= '0' &&
lpInputBuffer[index] <= '9');
i++; // next token
}
else if ((lpInputBuffer[index] >= 'A' && lpInputBuffer[index] <= 'Z') ||
(lpInputBuffer[index] >= 'a' && lpInputBuffer[index] <= 'z')) {
//
// we have a string, should be a day, month, or GMT
// lets skim to the end of the string
//
rgdwDateParseResults[i] =
MapDayMonthToDword(lpInputBuffer, index);
iLastLettered = i;
// We want to ignore the possibility of a time zone such as PST or EST in a non-standard
// date format such as "Thu Dec 17 16:01:28 PST 1998" (Notice that the year is _after_ the time zone
if ((rgdwDateParseResults[i] == DATE_TOKEN_ERROR)
&&
!(fIsANSIDateFormat && (i==DATE_ANSI_INDEX_YEAR))) {
fRet = false;
goto quit;
}
//
// At this point if we have a vaild string
// at this index, we know for sure that we're
// looking at a ANSI type DATE format.
//
if (i == DATE_ANSI_INDEX_MONTH) {
fIsANSIDateFormat = true;
}
//
// Read past the end of the current set of alpha characters,
// as MapDayMonthToDword only peeks at a few characters
//
do {
index++;
} while (index < DateString.Length &&
( (lpInputBuffer[index] >= 'A' && lpInputBuffer[index] <= 'Z') ||
(lpInputBuffer[index] >= 'a' && lpInputBuffer[index] <= 'z') ));
i++; // next token
}
else {
//
// For the generic case its either a space, comma, semi-colon, etc.
// the point is we really don't care, nor do we need to waste time
// worring about it (the orginal code did). The point is we
// care about the actual date information, So we just advance to the
// next lexume.
//
//.........这里部分代码省略.........
示例4: GetBytes
public virtual int GetBytes(String s, int charIndex, int charCount,
byte[] bytes, int byteIndex)
{
if (s == null)
throw new ArgumentNullException("s");
Contract.EndContractBlock();
return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex);
}
示例5: GetByteCount
public virtual int GetByteCount(String s)
{
if (s == null)
throw new ArgumentNullException("s");
Contract.EndContractBlock();
char[] chars = s.ToCharArray();
return GetByteCount(chars, 0, chars.Length);
}
示例6: ExponentialFormatter
private static String ExponentialFormatter(String input, int precision, NumberFormatInfo nfi)
{
bool IsNeg = false;
Char[] temp = input.ToCharArray();
Char[] temp2;
String output = String.Empty;
String digits;
Char exp = 'E';
if (precision < 0)
{
precision = -precision;
exp = 'e';
}
if (input.StartsWith(nfi.NegativeSign))
{
temp = new String(temp, nfi.NegativeSign.Length, temp.Length - nfi.NegativeSign.Length).ToCharArray();
IsNeg = true;
}
digits = (temp.Length - 1).ToString();
digits = ZeroString(3 - digits.Length) + digits;
temp2 = temp;
temp = new Char[precision + 2];
for (int j = 0; j < temp.Length; j++)
{
if ((j < 100) && (j < temp2.Length))
{
temp[j] = temp2[j];
}
else
{
temp[j] = '0';
}
}
int i = precision + 1;
if (temp[i] >= '5')
{
i--;
while ((i >= 0) && (temp[i] == '9'))
{
temp[i] = '0';
i--;
};
if (i > -1)
{
temp[i]++;
}
else
{
temp[0] = '1';
digits = (Int32.Parse(digits) + 1).ToString("D3");
i = 0;
}
}
else
{
i--;
}
if (IsNeg)
{
output = nfi.NegativeSign;
}
output = output + temp[0];
if (precision != 0)
{
output = output + nfi.NumberDecimalSeparator + new String(temp, 1, precision);
}
output = output + exp + nfi.PositiveSign + digits;
return output;
}
示例7: Parse
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public static SqlDecimal Parse(String s)
{
if (s == null)
throw new ArgumentNullException(nameof(s));
if (s == SQLResource.NullString)
return SqlDecimal.Null;
SqlDecimal snResult = SqlDecimal.Null;
char[] rgwchStr = s.ToCharArray();
int cwchStr = rgwchStr.Length;
int iData; //index to string
char usChar; //current value in string
int lDecPnt = -1; //position of decimal point in string
int iCurChar = 0;
//Must initialize precision and scale to valid values
snResult.m_bPrec = 1;
snResult.m_bScale = 0;
//Must initialize *this to zero
snResult.SetToZero();
// Trim trailing blanks.
while (cwchStr != 0 && rgwchStr[cwchStr - 1] == ' ')
cwchStr--;
// If string contains only spaces, stop
if (cwchStr == 0)
throw new FormatException(SQLResource.FormatMessage);
// Trim leading blanks.
while (rgwchStr[iCurChar] == ' ')
{
iCurChar++;
cwchStr--;
}
// Get sign for numeric value.
if (rgwchStr[iCurChar] == '-')
{
snResult.SetSignBit(false);
iCurChar++;
cwchStr--;
}
else
{
snResult.SetSignBit(true);
if (rgwchStr[iCurChar] == '+')
{
iCurChar++;
cwchStr--;
}
}
// Hack: Check for "0.". If so, replace by ".0".
while ((cwchStr > 2) && (rgwchStr[iCurChar] == '0'))
{
iCurChar++;
cwchStr--;
}
if (2 == cwchStr && '0' == rgwchStr[iCurChar] && '.' == rgwchStr[iCurChar + 1])
{
rgwchStr[iCurChar] = '.';
rgwchStr[iCurChar + 1] = '0';
}
// Invalid string?
if (cwchStr == 0 || cwchStr > s_NUMERIC_MAX_PRECISION + 1)
throw new FormatException(SQLResource.FormatMessage);
// Trim leading zeros. (There shouldn't be any except for floats
// less than 1. e.g. 0.01)
while ((cwchStr > 1) && (rgwchStr[iCurChar] == '0'))
{
iCurChar++;
cwchStr--;
}
// Convert string to numeric value by looping through input string.
for (iData = 0; iData < cwchStr; iData++)
{
usChar = rgwchStr[iCurChar];
iCurChar++;
if (usChar >= '0' && usChar <= '9')
usChar -= '0';
else if (usChar == '.' && lDecPnt < 0)
{
lDecPnt = iData;
continue;
}
else
throw new FormatException(SQLResource.FormatMessage);
//.........这里部分代码省略.........
示例8: WriteTextEncodedAttribute
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
protected internal void WriteTextEncodedAttribute(String attribute, String value) {
// Unlike HTML encoding, we need to replace $ with $$, and <> with < and >.
// We can't do this by piggybacking HtmlTextWriter.WriteAttribute, because it
// would translate the & in < or > to &. So we more or less copy the
// ASP.NET code that does similar encoding.
Write(' ');
Write(attribute);
Write("=\"");
int cb = value.Length;
int pos = value.IndexOfAny(_attributeCharacters);
if (pos == -1) {
Write(value);
}
else {
char[] s = value.ToCharArray();
int startPos = 0;
while (pos < cb) {
if (pos > startPos) {
Write(s, startPos, pos - startPos);
}
char ch = s[pos];
switch (ch) {
case '\"':
Write(""");
break;
case '&':
Write("&");
break;
case '<':
Write("<");
break;
case '>':
Write(">");
break;
case '$':
Write("$$");
break;
}
startPos = pos + 1;
pos = value.IndexOfAny(_attributeCharacters, startPos);
if (pos == -1) {
Write(s, startPos, cb - startPos);
break;
}
}
}
Write('\"');
}
示例9: Variation_11
public int Variation_11()
{
int size = (1 << 24);
string str = "";
char[] ach = str.ToCharArray();
bool fRetry = false;
for (; ;)
{
try
{
str = new String('Z', size);
ach = str.ToCharArray();
}
catch (OutOfMemoryException exc)
{
size >>= 1;
CError.WriteLine(exc + " : " + exc.Message + " Retry with " + size);
fRetry = true;
}
if (size < (1 << 30))
{
fRetry = true;
}
if (fRetry)
{
CError.WriteLine("Tested size == " + size);
if (str == null)
CError.WriteLine("string is null");
break;
}
}
object objActual = DataReader.NameTable.Get(ach, 0, ach.Length);
object objActual1 = DataReader.NameTable.Get(ach, 0, ach.Length);
CError.Compare(objActual, objActual1, CurVariation.Desc);
VerifyNameTableGet(objActual, str, ach, 0, ach.Length);
return TEST_PASS;
}
示例10: GetBytes
private byte[] GetBytes(String str)
{
byte[] bytes = new byte[str.Length * sizeof(char)];
System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
}
示例11: ToString
public String ToString(String myString)
{
String str = "{";
Char[] chars = myString.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
str = str + @"\u" + String.Format("{0:X04}", (int)chars[i]);
if (i != chars.Length - 1) str = str + ",";
}
str = str + "}";
return str;
}
示例12: EncodeSpecialViewState
internal String EncodeSpecialViewState(String pageState) {
// Mobile Internet Toolkit 5093.
// Note: This 'trades' certain characters for other characters, so applying it twice is an identity
// transformation.
char[] viewstate = pageState.ToCharArray();
for (int i = 0; i < viewstate.Length; i++) {
char currentChar = viewstate[i];
// Only check character replacement if within the range
if (currentChar < _specialEncodingChars.Length) {
char encodingChar = _specialEncodingChars[currentChar];
if (encodingChar != '\0') {
viewstate[i] = encodingChar;
}
}
}
return new String(viewstate);
}
示例13: Write
// Writes a length-prefixed string to this stream in the BinaryWriter's
// current Encoding. This method first writes the length of the string as
// a four-byte unsigned integer, and then writes that many characters
// to the stream.
//
public unsafe virtual void Write(String value)
{
if (value == null)
throw new ArgumentNullException("value");
int len = _encoding.GetByteCount(value);
Write7BitEncodedInt(len);
if (_largeByteBuffer == null)
{
_largeByteBuffer = new byte[LargeByteBufferSize];
_maxChars = LargeByteBufferSize / _encoding.GetMaxByteCount(1);
}
if (len <= LargeByteBufferSize)
{
//Contract.Assert(len == _encoding.GetBytes(chars, 0, chars.Length, _largeByteBuffer, 0), "encoding's GetByteCount & GetBytes gave different answers! encoding type: "+_encoding.GetType().Name);
_encoding.GetBytes(value, 0, value.Length, _largeByteBuffer, 0);
OutStream.Write(_largeByteBuffer, 0, len);
}
else
{
// Aggressively try to not allocate memory in this loop for
// runtime performance reasons. Use an Encoder to write out
// the string correctly (handling surrogates crossing buffer
// boundaries properly).
int charStart = 0;
int numLeft = value.Length;
while (numLeft > 0)
{
// Figure out how many chars to process this round.
int charCount = (numLeft > _maxChars) ? _maxChars : numLeft;
int byteLen;
fixed (char* pChars = &value.ToCharArray()[0])
{
fixed (byte* pBytes = &_largeByteBuffer[0])
{
byteLen = _encoder.GetBytes(pChars + charStart, charCount, pBytes, LargeByteBufferSize, charCount == numLeft);
}
}
OutStream.Write(_largeByteBuffer, 0, byteLen);
charStart += charCount;
numLeft -= charCount;
}
}
}
示例14: execProlog
private string execProlog(String str)
{
StringBuilder sb = new StringBuilder();
sb.Append("Exec: " + str);
engine.SetCurrentOutput(new StringWriter(sb));
bool result = false;
if (str != null)
{
String query = new String(str.ToCharArray());
result = engine.ExecuteQuery(ref query);
if (query == null) return sb.ToString();
}
else
{
result = engine.More();
}
engine.TryCloseCurrentOutput();
if (!result)
sb.Append(PrologEngine.NO + "\n");
else
sb.Append(engine.Answer + "\n");
Console.WriteLine(sb.ToString());
return sb.ToString();
}
示例15: AppendFormat
public StringBuilder AppendFormat(IFormatProvider provider, String format, params Object[] args)
{
if (format == null || args == null)
{
throw new ArgumentNullException((format == null) ? "format" : "args");
}
char[] chars = format.ToCharArray(0, format.Length);
int pos = 0;
int len = chars.Length;
char ch = '\x0';
ICustomFormatter cf = null;
if (provider != null)
{
cf = (ICustomFormatter)provider.GetFormat(typeof(ICustomFormatter));
}
while (true)
{
int p = pos;
int i = pos;
while (pos < len)
{
ch = chars[pos];
pos++;
if (ch == '}')
{
if (pos < len && chars[pos] == '}') // Treat as escape character for }}
pos++;
else
FormatError();
}
if (ch == '{')
{
if (pos < len && chars[pos] == '{') // Treat as escape character for {{
pos++;
else
{
pos--;
break;
}
}
chars[i++] = ch;
}
if (i > p) Append(chars, p, i - p);
if (pos == len) break;
pos++;
if (pos == len || (ch = chars[pos]) < '0' || ch > '9') FormatError();
int index = 0;
do
{
index = index * 10 + ch - '0';
pos++;
if (pos == len) FormatError();
ch = chars[pos];
} while (ch >= '0' && ch <= '9' && index < 1000000);
if (index >= args.Length) throw new Exception("IndexOutOfRange");
while (pos < len && (ch = chars[pos]) == ' ') pos++;
bool leftJustify = false;
int width = 0;
if (ch == ',')
{
pos++;
while (pos < len && chars[pos] == ' ') pos++;
if (pos == len) FormatError();
ch = chars[pos];
if (ch == '-')
{
leftJustify = true;
pos++;
if (pos == len) FormatError();
ch = chars[pos];
}
if (ch < '0' || ch > '9') FormatError();
do
{
width = width * 10 + ch - '0';
pos++;
if (pos == len) FormatError();
ch = chars[pos];
} while (ch >= '0' && ch <= '9' && width < 1000000);
}
while (pos < len && (ch = chars[pos]) == ' ') pos++;
Object arg = args[index];
String fmt = null;
if (ch == ':')
{
pos++;
p = pos;
i = pos;
while (true)
{
if (pos == len) FormatError();
ch = chars[pos];
pos++;
//.........这里部分代码省略.........