Skip to content

Commit 9a81105

Browse files
TylerMSFTTylerMSFT
authored andcommitted
fix link
1 parent 760484b commit 9a81105

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

docs/text/how-to-convert-between-various-string-types.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ This topic shows how to convert various Visual C++ string types into other strin
1111

1212
The strings types that are covered include `char *`, `wchar_t*`, [`_bstr_t`](../cpp/bstr-t-class.md), [`CComBSTR`](../atl/reference/ccombstr-class.md), [`CString`](../atl-mfc-shared/using-cstring.md), [`basic_string`](../standard-library/basic-string-class.md), and <xref:System.String?displayProperty=fullName>.
1313

14-
In all cases, a copy of the string is made when converted to the new type. Any changes made to the new string will not affect the original string, and vice versa.
14+
In all cases, a copy of the string is made when converted to the new type. Any changes made to the new string won't affect the original string, and vice versa.
1515

16-
For more background information about converting narrow and wide strings, see [Background: converting between narrow strings and wide strings](#background-converting-between-narrow-strings-and-wide-strings)
16+
For more background information about converting narrow and wide strings, see [Background: converting between narrow strings and wide strings](#background-converting-between-narrow-and-wide-strings).
1717

1818
## Example: Convert from `char *`
1919

2020
### Description
2121

22-
This example demonstrates how to convert from a `char *` to the string types listed above. A `char *` string (also known as a C-style string) uses a null character to indicate the end of the string. C-style strings usually require one byte per character, but can also use two bytes. In the examples below, `char *` strings are sometimes referred to as multibyte character strings because of the string data that results from converting from Unicode strings. Single byte and multibyte character (`MBCS`) functions can operate on `char *` strings.
22+
This example demonstrates how to convert from a `char *` to the string types listed above. A `char *` string (also known as a C-style string) uses a null character to indicate the end of the string. C-style strings usually require 1 byte per character, but can also use 2 bytes. In the examples below, `char *` strings are sometimes referred to as multibyte character strings because of the string data that results from converting from Unicode strings. Single byte and multibyte character (`MBCS`) functions can operate on `char *` strings.
2323

2424
### Code
2525

@@ -159,7 +159,7 @@ int main()
159159
// character in the input string (including a wide character
160160
// null). Because a multibyte character can be one or two bytes,
161161
// you should allot two bytes for each character. Having extra
162-
// space for the new string is not an error, but having
162+
// space for the new string isn't an error, but having
163163
// insufficient space is a potential security problem.
164164
const size_t newsize = origsize*2;
165165
// The new string will contain a converted copy of the original
@@ -240,7 +240,7 @@ Hello, World! (System::String)
240240

241241
### Description
242242

243-
This example demonstrates how to convert from a `_bstr_t` to other string types. The `_bstr_t` object encapsulates wide character `BSTR` strings. A `BSTR` string has a length value and does not use a null character to terminate the string, but the string type you convert to may require a terminating `NULL`.
243+
This example demonstrates how to convert from a `_bstr_t` to other string types. The `_bstr_t` object encapsulates wide character `BSTR` strings. A `BSTR` string has a length value and doesn't use a null character to terminate the string, but the string type you convert to may require a terminating `NULL`.
244244

245245
### Code
246246

@@ -338,7 +338,7 @@ Hello, World! (System::String)
338338

339339
### Description
340340

341-
This example demonstrates how to convert from a `CComBSTR` to other string types. Like `_bstr_t`, a `CComBSTR` object encapsulates wide character `BSTR` strings. A `BSTR` string has a length value and does not use a null character to terminate the string, but the string type you convert to may require a terminating `NULL`.
341+
This example demonstrates how to convert from a `CComBSTR` to other string types. Like `_bstr_t`, a `CComBSTR` object encapsulates wide character `BSTR` strings. A `BSTR` string has a length value and doesn't use a null character to terminate the string, but the string type you convert to may require a terminating `NULL`.
342342

343343
### Code
344344

@@ -394,7 +394,7 @@ int main()
394394
wcscpy_s(wcstring, widesize, orig);
395395
wcscat_s(wcstring, widesize, strConcat);
396396

397-
// Display the result. Unlike CStringW, a wchar_t does not need
397+
// Display the result. Unlike CStringW, a wchar_t doesn't need
398398
// a cast to (LPCTSTR) with wcout.
399399
wcout << wcstring << endl;
400400

@@ -446,9 +446,9 @@ Hello, World! (System::String)
446446

447447
### Description
448448

449-
This example demonstrates how to convert from a `CString` to other string types. `CString` is based on the TCHAR data type, which in turn depends on whether the symbol `_UNICODE` is defined. If `_UNICODE` is not defined, `TCHAR` is defined to be `char` and `CString` contains a multibyte character string; if `_UNICODE` is defined, `TCHAR` is defined to be **`wchar_t`** and `CString` contains a wide character string.
449+
This example demonstrates how to convert from a `CString` to other string types. `CString` is based on the TCHAR data type, which in turn depends on whether the symbol `_UNICODE` is defined. If `_UNICODE` isn't defined, `TCHAR` is defined to be `char` and `CString` contains a multibyte character string; if `_UNICODE` is defined, `TCHAR` is defined to be **`wchar_t`** and `CString` contains a wide character string.
450450

451-
`CStringA` contains the `char` type and supports single-byte or multibyte strings. `CStringW` is the wide character version. Neither `CStringA` nor `CStringW` use `_UNICODE` to determine how they should compile. `CStringA` and `CStringW` are used in this example to clarify minor differences in buffer size allocation and output handling.
451+
`CStringA` contains the `char` type and supports single-byte or multibyte strings. `CStringW` is the wide character version. `CStringA` and `CStringW` don't use `_UNICODE` to determine how they should compile. `CStringA` and `CStringW` are used in this example to clarify minor differences in buffer size allocation and output handling.
452452

453453
### Code
454454

@@ -795,9 +795,9 @@ There's a mismatch in the way that `CStringA` performs wide to narrow conversion
795795

796796
`CStringA` passes `CP_THREAD_ACP`, which means to use the current thread code page, to the narrowing conversion method. But `string.ctor(sbyte*)` passes `CP_ACP`, which means to use the current system code page, to the widening conversion method. If the system and thread code pages are out of sync, it can cause round-trip data corruption.
797797

798-
To reconcile this difference, there's a constant definition you can include in your C program to get it to use `CP_ACP` (like .NET) instead of `CP_THREAD_ACP`. For more information, see [_CONVERSION_DONT_USE_THREAD_LOCALE](https://social.msdn.microsoft.com/Forums/vstudio/en-US/f3820781-c418-40bf-8c4f-7250001e5b68/visual-studio-2015-update-1-implicit-string-narrow-wide-conversion-and).
798+
To reconcile this difference, you can use the constant `_CONVERSION_DONT_USE_THREAD_LOCALE`) to get it to use `CP_ACP` (like .NET) instead of `CP_THREAD_ACP`. For more information, see [_CONVERSION_DONT_USE_THREAD_LOCALE](https://social.msdn.microsoft.com/Forums/vstudio/en-US/f3820781-c418-40bf-8c4f-7250001e5b68/visual-studio-2015-update-1-implicit-string-narrow-wide-conversion-and).
799799

800-
Another approach is to `pinvoke` [`GetThreadLocale`](/windows/win32/api/winnls/nf-winnls-getthreadlocale) and use the returned `LCID` to create a [`CultureInfo`](/dotnet/api/system.globalization.cultureinfo?view=net-6.0), and then use `CultureInfo.TextInfo` to get the code page you can use in the conversion.
800+
Another approach is to `pinvoke` [`GetThreadLocale`](/windows/win32/api/winnls/nf-winnls-getthreadlocale) and use the returned `LCID` to create a [`CultureInfo`](/dotnet/api/system.globalization.cultureinfo?view=net-6.0). Then use `CultureInfo.TextInfo` to get the code page you can use in the conversion.
801801

802802
## See also
803803

0 commit comments

Comments
 (0)