本文整理汇总了C++中StringBuffer::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ StringBuffer::ToString方法的具体用法?C++ StringBuffer::ToString怎么用?C++ StringBuffer::ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuffer
的用法示例。
在下文中一共展示了StringBuffer::ToString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testAppendDoubleFloat
void testAppendDoubleFloat()
{
printf("\n==== Enter testAppendDoubleFloat ====\n");
{
Double d = Math::DOUBLE_MAX_VALUE;
StringBuffer sb;
String str;
// sb.AppendDouble(d);
// str = sb.ToString();
// printf(" >> Append Double %e, %s\n", d, str.string());
//
// d = Math::DOUBLE_MIN_VALUE;
// sb.Reset();
// sb.AppendDouble(d);
// str = sb.ToString();
// printf(" >> Append Double %e, %s\n", d, str.string());
//
// d = 9999912345.54321;
// sb.Reset();
// sb.AppendDouble(d);
// str = sb.ToString();
// printf(" >> Append Double %e, %s\n", d, str.string());
d = 2013.0806;
sb.Reset();
sb.AppendDouble(d);
str = sb.ToString();
printf(" >> Append Double %e, %s\n", d, str.string());
float f = 2013.0806;
sb.Reset();
sb.AppendFloat(f);
str = sb.ToString();
printf(" >> Append Float %e, %s\n", f, str.string());
// Float f = Math::FLOAT_MAX_VALUE;
// sb.Reset();
// sb.AppendFloat(f);
// str = sb.ToString();
// printf(" >> Append Float %e, %s\n", f, str.string());
//
// f = Math::FLOAT_MIN_VALUE;
// sb.Reset();
// sb.AppendFloat(f);
// str = sb.ToString();
// printf(" >> Append Float %e, %s\n", f, str.string());
//
// f = 12345.54321F;
// sb.Reset();
// sb.AppendFloat(f);
// str = sb.ToString();
// printf(" >> Append Float %f, %s\n", f, str.string());
}
printf("==== Leave testAppendDoubleFloat ====\n");
}
示例2: ToString
// @Override
ECode CWifiInfo::ToString(
/* [out] */ String* str)
{
StringBuffer sb;
String none("<none>");
sb.Append("SSID: ");
String sidStr;
mWifiSsid->ToString(&sidStr);
sb.Append(mWifiSsid == NULL ? IWifiSsid::NONE : sidStr);
sb.Append(", BSSID: ");
sb.Append(mBSSID.IsNull() ? none : mBSSID);
sb.Append(", MAC: ");
sb.Append(mMacAddress.IsNull() ? none : mMacAddress);
sb.Append(", Supplicant state: ");
if (mSupplicantState == NULL) sb.Append(none);
sb.Append(mSupplicantState);
sb.Append(", RSSI: ");
sb.Append(mRssi);
sb.Append(", Link speed: ");
sb.Append(mLinkSpeed);
sb.Append(", Net ID: ");
sb.Append(mNetworkId);
sb.Append(", Metered hint: ");
sb.AppendBoolean(mMeteredHint);
*str = sb.ToString();
return NOERROR;
}
示例3: ToString
//@Override
ECode CBatchedScanSettings::ToString(
/* [out] */ String* str)
{
VALIDATE_NOT_NULL(str);
StringBuffer sb;
String none("<none>");
sb.Append("BatchScanSettings [maxScansPerBatch: ");
if (mMaxScansPerBatch == UNSPECIFIED) {
sb.Append(none);
}
else {
sb.Append(mMaxScansPerBatch);
}
sb.Append(", maxApPerScan: ");
if (mMaxScansPerBatch == UNSPECIFIED) {
sb.Append(none);
}
else {
sb.Append(mMaxApPerScan);
}
sb.Append(", scanIntervalSec: ");
if (mMaxScansPerBatch == UNSPECIFIED) {
sb.Append(none);
}
else {
sb.Append(mScanIntervalSec);
}
sb.Append(", maxApForDistance: ");
if (mMaxScansPerBatch == UNSPECIFIED) {
sb.Append(none);
}
else {
sb.Append(mMaxApForDistance);
}
sb.Append(", channelSet: ");
if (mChannelSet == NULL) {
sb.Append("ALL");
}
else {
sb.Append("<");
AutoPtr<IIterator> iter;
mChannelSet->GetIterator((IIterator**)&iter);
Boolean bNext;
iter->HasNext(&bNext);
for (; bNext; iter->HasNext(&bNext)) {
AutoPtr<ICharSequence> channel;
iter->GetNext((IInterface**)&channel);
String str;
channel->ToString(&str);
sb.Append(" ");
sb.Append(str);
}
sb.Append(">");
}
sb.Append("]");
return sb.ToString(str);
}
示例4: ToString
ECode UsbAccessory::ToString(
/* [out] */ String* str)
{
VALIDATE_NOT_NULL(str);
StringBuffer buf;
buf += "UsbAccessory[mManufacturer=";
buf += mManufacturer;
buf += ", mModel=";
buf += mModel;
buf += ", mDescription=";
buf += mDescription;
buf += ", mVersion=";
buf += mVersion;
buf += ", mUri=";
buf += mUri;
buf += ", mSerial=";
buf += mSerial;
buf += "]";
buf.ToString(str);
return NOERROR;
}
示例5: ToString
ECode CUsbDevice::ToString(
/* [out] */ String* str)
{
VALIDATE_NOT_NULL(str);
StringBuffer buf;
buf += "UsbDevice[mName=";
buf += mName;
buf += ",mVendorId=";
buf += mVendorId;
buf += ",mProductId=";
buf += mProductId;
buf += ",mClass=";
buf += mClass;
buf += ",mSubclass=";
buf += mSubclass;
buf += ",mProtocol=";
buf += mProtocol;
buf += "]";
buf.ToString(str);
return NOERROR;
}
示例6: String
/**
* Trim leading zeros from IPv4 address strings
* Our base libraries will interpret that as octel..
* Must leave non v4 addresses and host names alone.
* For example, 192.168.000.010 -> 192.168.0.10
* TODO - fix base libraries and remove this function
* @param addr a string representing an ip addr
* @return a string propertly trimmed
*/
String NetworkUtils::TrimV4AddrZeros(
/* [in] */ const String& addr)
{
if (addr.IsNull()) {
return String(NULL);
}
AutoPtr<ArrayOf<String> > octets;
StringUtils::Split(addr, String("\\."), (ArrayOf<String>**)&octets);
if (octets->GetLength() != 4) {
return addr;
}
StringBuffer buff;
for (Int32 i = 0; i < 4; i++) {
// try {
if ((*octets)[i].GetLength() > 3) {
return addr;
}
buff += (*octets)[i];
// } catch (NumberFormatException e) {
// return addr;
// }
if (i < 3)
buff += String(".");
}
return buff.ToString();
}
示例7: constructor
ECode AttributedString::constructor(
/* [in] */ IAttributedCharacterIterator* iterator)
{
VALIDATE_NOT_NULL(iterator)
ICharacterIterator* ci = ICharacterIterator::Probe(iterator);
Int32 bi, ei;
ci->GetBeginIndex(&bi);
ci->GetEndIndex(&ei);
if (bi > ei) {
ALOGE("AttributedString::constructor(): IllegalArgumentException, invalid substring range.");
//throw new IllegalArgumentException("Invalid substring range");
return E_ILLEGAL_ARGUMENT_EXCEPTION;
}
StringBuffer buffer;
for (Int32 i = bi; i < ei; i++) {
Char32 cv, nv;
ci->GetCurrent(&cv);
buffer += cv;
ci->GetNext(&nv);
}
buffer.ToString(&mText);
AutoPtr<ISet> attributes;
iterator->GetAllAttributeKeys((ISet**)&attributes);
if (attributes == NULL) {
return NOERROR;
}
AutoPtr<IIterator> it;
attributes->GetIterator((IIterator**)&it);
Boolean hasNext;
IAttributedCharacterIteratorAttribute* attr;
Char32 ch, cv;
Int32 start, limit;
while(it->HasNext(&hasNext), hasNext) {
AutoPtr<IInterface> obj;
it->GetNext((IInterface**)&obj);
attr = IAttributedCharacterIteratorAttribute::Probe(obj);
ci->SetIndex(0, &ch);
while (ci->GetCurrent(&cv), cv != (Char32)ICharacterIterator::DONE) {
iterator->GetRunStart(attr, &start);
iterator->GetRunLimit(attr, &limit);
AutoPtr<IInterface> value;
iterator->GetAttribute(attr, (IInterface**)&value);
if (value != NULL) {
AddAttribute(attr, value, start, limit);
}
ci->SetIndex(limit, &ch);
}
}
return NOERROR;
}
示例8: OnShowNext
ECode CDispList::OnShowNext()
{
// get the current showing item's index in the array.
Int32 index = -1;
AutoPtr<CDispListHelper> helper = GetHelper();
AutoPtr<ArrayOf<IInteger32*> > array = helper->mShortCutArray;
for(Int32 i = 0; i < array->GetLength(); i++)
{
AutoPtr<IInteger32> temp = (*array)[i];
Int32 v;
temp->GetValue(&v);
if(v == mCurItem)
{
index = i;
break;
}
}
{
String str;
StringBuffer sb;
sb += "current index = ";
sb += index;
sb.ToString(&str);
Logger::D(IDispList::TAG, str);
}
if( index == -1 )
return NOERROR;
// get the index of the next item to be shown
index++;
if( index == array->GetLength() )
index = 0;
AutoPtr<IInteger32> key = (*array)[index];
AutoPtr<IDispListDispFormat> format;
HashMap<AutoPtr<IInteger32>, AutoPtr<IDispListDispFormat> >::Iterator it =
helper->mShortCutFormatMap.Find(key);
if(it != helper->mShortCutFormatMap.End())
{
format = it->mSecond;
}
return OnShowItem(format);
}
示例9: OnShowItem
ECode CDispList::OnShowItem(
/* [in] */ IDispListDispFormat* item)
{
// get a item's string id
AutoPtr<CDispListHelper> helper = GetHelper();
Int32 advType;
helper->GetAdvancedDisplayType(item, &advType);
AutoPtr<IInteger32> key;
CInteger32::New(advType, (IInteger32**)&key);
AutoPtr<IInteger32> str_id;
HashMap<AutoPtr<IInteger32>, AutoPtr<IInteger32> >::Iterator it =
helper->mShortCutStrMap.Find(key);
if(it != helper->mShortCutStrMap.End())
{
str_id = it->mSecond;
}
if( str_id == NULL ){
String itemStr;
item->ToString(&itemStr);
StringBuffer sb;
sb += "Fail in searching item = ";
sb += itemStr;
sb.ToString(&itemStr);
Logger::D(IDispList::TAG, itemStr);
return NOERROR;
}
// redraw TextView and show toast
Int32 value;
str_id->GetValue(&value);
mToast->SetText(value);
mToast->Show();
// record the current showing item
mCurItem = advType;
return NOERROR;
}
示例10: testMisc
void testMisc()
{
printf("\n==== Leave testAutoPtr ====\n");
{
StringBuffer sb(20);
String str;
for (Int32 i = 0; i < 20; i++) {
sb.AppendChar('A' + i);
}
str = sb.ToString();
printf(" >> Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
sb.TrimToSize();
printf(" >> Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
}
{
StringBuffer sb;
String str;
for (Int32 i = 0; i < 20; i++) {
sb.AppendChar('A' + i);
}
sb.InsertString(0, String("0123456789"));
str = sb.ToString();
printf("\n >> InsertString Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
}
{
StringBuffer sb;
String str;
sb.AppendNULL();
str = sb.ToString();
printf("\n >> AppendNULL Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
}
{
StringBuffer sb(5);
String str;
for (Int32 i = 0; i < 5; ++i) {
sb.AppendChar('1' + i);
}
str = sb.ToString();
printf("\n >> BeforeReplace Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
sb.Replace(0, 5, String("ABCDE"));
str = sb.ToString();
printf(" >> AfterReplace Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
sb.Replace(0, 4, String("444"));
str = sb.ToString();
printf(" >> AfterReplace Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
sb.Replace(0, 3, String("UVWXYZ"));
str = sb.ToString();
printf(" >> AfterReplace Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
sb.Replace(0, 7, String("1234567"));
str = sb.ToString();
printf(" >> AfterReplace Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
sb.Replace(0, 0, String("ABC"));
str = sb.ToString();
printf(" >> AfterReplace Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
sb.Replace(0, 10, String("0123456789"));
str = sb.ToString();
printf(" >> AfterReplace Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
sb.Replace(10, 10, String("ABC"));
str = sb.ToString();
printf(" >> AfterReplace Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
sb.Replace(14, 18, String("XYZ"));
str = sb.ToString();
printf(" >> AfterReplace Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
sb.Replace(12, 13, String("0"));
str = sb.ToString();
printf(" >> AfterReplace Capacity %d, length %d, str: %s\n", sb.mCapacity, sb.GetLength(), str.string());
}
printf("==== Leave testAutoPtr ====\n");
}
示例11: testStringBuffer
void testStringBuffer()
{
printf("==== Enter testStringBuffer ====\n");
printf("\n === Construct === \n");
StringBuffer sbc(String("Construct from String"));
String str = sbc.ToString();
printf(" > Construct:\n%s\n", (const char*)str);
printf("\n === Append === \n");
Char32 a = 'A';
StringBuffer sb;
ECode ec = sb.ToString(&str);
printf(">> Get string from emtpy StringBuffer %s, %08x - %08x\n", str.string(), NOERROR, ec);
sb.AppendCStr(">>Start\n");
sb.AppendNULL();
sb.AppendChar('_');
sb.AppendChar(a);
sb.AppendChar('_');
sb.AppendBoolean(TRUE);
sb.AppendChar('_');
sb.AppendBoolean(FALSE);
sb.AppendChar('_');
sb.AppendInt32(32);
sb.AppendChar('_');
sb.AppendInt32(-32);
sb.AppendChar('_');
sb.AppendInt64(64);
sb.AppendChar('_');
sb.AppendInt64(-64);
sb.AppendChar('_');
sb.AppendFloat(10.0f);
sb.AppendChar('_');
sb.AppendDouble(101010.1010);
sb.AppendChar('_');
sb.AppendString(String("String"));
sb.AppendCStr("\n<<End");
str = sb.ToString();
printf(" > AppendTest:\n%s\n", (const char*)str);
printf("\n === Index ===\n");
Int32 index = 0;
String subStr("32");
sb.IndexOf(subStr, &index);
printf(" > IndexOf %s is %d\n", (const char*)subStr, index);
subStr = String("_NOT_");
sb.IndexOf(subStr, &index);
printf(" > IndexOf %s is %d\n", (const char*)subStr, index);
subStr = String("32");
sb.LastIndexOf(subStr, &index);
printf(" > LastIndexOf %s is %d\n", (const char*)subStr, index);
subStr = String("_NOT_");
sb.LastIndexOf(subStr, &index);
printf(" > LastIndexOf %s is %d\n", (const char*)subStr, index);
printf("\n === Substring ===\n");
Int32 start = 30, end = 32;
sb.Substring(start, &subStr);
printf(" > Substring from %d is : %s\n", start, (const char*)subStr);
sb.SubstringEx(start, end, &subStr);
printf(" > Substring from %d to %d is : %s\n", start, end, (const char*)subStr);
printf("\n === Get ===\n");
Char32 ch = 0;
sb.GetChar(start, &ch);
printf(" > GetChar at %d is : %c\n", start, ch);
sb.GetLength(&end);
printf(" > GetLength is : %d\n", end);
sb.GetByteCount(&end);
printf(" > GetByteCount is : %d\n", end);
sb.GetCapacity(&end);
printf(" > GetCapacity is : %d\n", end);
printf("\n === Set/Replace/Insert ===\n");
sb.SetChar(13, 'B');
sb.ToString(&str);
printf(" > SetCharAt:\n%s\n", (const char*)str);
sb.Replace(15, 15 + 4, String("Replace"));
sb.ToString(&str);
printf(" > Replace:\n%s\n", (const char*)str);
sb.InsertString(15, String("Insert_"));
sb.ToString(&str);
printf(" > InsertString:\n%s\n", (const char*)str);
sb.InsertString(0, String("HeadInsert_"));
sb.ToString(&str);
printf(" > InsertString in head:\n%s\n", (const char*)str);
sb.InsertChar(19, '_');
sb.ToString(&str);
printf(" > InsertChar:\n%s\n", (const char*)str);
sb.InsertBoolean(19, TRUE);
sb.ToString(&str);
//.........这里部分代码省略.........