字符串输出

Posted ye_ming

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串输出相关的知识,希望对你有一定的参考价值。

utf-8 标识符 0xEF 0xBB 0xBF

CStdioFile file;

if (file.Open(strConfigFileDir, CFile::modeReadWrite | CFile::modeNoTruncate | CFile::modeCreate))
    {

       BYTE head[3];
        CString strFile;
        file.Read(head, 3);//BOM头 EF BB BF
        file.ReadString(strFile);
        if (!(head[0] == 0xEF && head[1] == 0xBB && head[2] == 0xBF))
        {
            file.SeekToBegin();
            
            const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF };
            file.Write(LeadBytes, sizeof(LeadBytes));
        }

    }

 

 Unicode 标识符:0XFEFF

        file.WriteString(L"0XFEFF");

 

文件打开方式插入字符串:

if (file.Open(strConfigFileDir, CFile::modeRead))
            {
                char chBuffer[512000] = { 0 };
                unsigned int bufferSize = sizeof(chBuffer) / sizeof(char);
                long lFileSize = file.GetLength();
                int times = lFileSize / bufferSize;
                if (lFileSize % bufferSize > 0)
                {
                    times++;
                }
                for (int i = 0; i < times; i++)
                {
                    file.Read(chBuffer, bufferSize);
                    spstrText->Append(chBuffer);                   
                }
                unsigned long iEndPos = spstrText->Find("</Config>");
                CStringA strOneRecord = spstrText->Mid(0, iEndPos);
                strOneRecord.Append(L"xxxxxxx");
             }
   file.Close();

 

Unicode 转utf-8

            CStringA utf8String(str);
            int nSrcLen = (int)wcslen(str);
            int nBufLen = (nSrcLen + 1) * 6;
            LPSTR buffer = utf8String.GetBufferSetLength(nBufLen);
            int nLen = AtlUnicodeToUTF8(str, nSrcLen, buffer, nBufLen);
            buffer[nLen] = 0;
            utf8String.ReleaseBuffer();

 

以上是关于字符串输出的主要内容,如果未能解决你的问题,请参考以下文章

php Yoast SEO规范输出的代码片段

php Yoast SEO规范输出的代码片段

php 在Yoast SEO中更改或删除OpenGraph输出的代码片段。此代码中有多个代码段。

php 一个短代码片段准备在WooCommerce Thank You页面上输出货件跟踪UI。

将多个输出中的hls属性设置为单独的片段代码

学习笔记:python3,代码片段(2017)