Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to convert a WideString to a String Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
05-Apr-03
Category
Object Pascal-Strings
Language
Delphi 3.x
Views
113
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to convert a WideString to a String

Answer:

Converts Unicode string to Ansi string using specified code page. 
  @param   ws       Unicode string. 
  @param   codePage Code page to be used in conversion. 
  @returns Converted ansi string. 

1   function WideStringToString(const ws: WideString; codePage: Word): 
2   AnsiString;
3   var
4     l: integer;
5   begin
6     if ws = ' then
7       Result := '
8   else
9     begin
10      l := WideCharToMultiByte(codePage,
11        WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR,
12        @ws[1], -1, nil, 0, nil, nil);
13      SetLength(Result, l - 1);
14      if l > 1 then
15        WideCharToMultiByte(codePage,
16          WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR,
17          @ws[1], -1, @Result[1], l - 1, nil, nil);
18    end;
19  end; { WideStringToString } 
20  
21  Converts Ansi string to Unicode string using specified code page. 
22    @param   s        Ansi string. 
23    @param   codePage Code page to be used in conversion. 
24    @returns Converted wide string. 
25  
26  function StringToWideString(const s: AnsiString; codePage: Word): WideString;
27  var
28    l: integer;
29  begin
30    if s = ' then
31      Result := '
32  else
33    begin
34      l := MultiByteToWideChar(codePage, MB_PRECOMPOSED, PChar(@s[1]), -1, nil, 0);
35      SetLength(Result, l - 1);
36      if l > 1 then
37        MultiByteToWideChar(CodePage, MB_PRECOMPOSED, PChar(@s[1]),
38          -1, PWideChar(@Result[1]), l - 1);
39    end;
40  end; { StringToWideString }



			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC