473,388 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

ansi string

Hi,
how can i create an ansi string in c#(not unicode)?
How can i convert a string member lets say string str="12345" to char*
s="12345" becuse the unicode "12345" is "1020304050" and i need to cinvert
it to char* in c# but i dont have pointers in c# so what can i do???

Thanks
Nov 17 '05 #1
2 23866
You most certainly do have pointers in C#, you simply have to declare an
unsafe code block to use them.

In C# though you should avoid unsafe code when possible. The string indexer
will return each character in a string, as will a foreach statement:

foreach (char c in myString) {
// do something with c
}

or:

for (int i = 0;i++;i < myString.Length) {
// do something with myString[i]
}

--Bob

"Dave" <be******@netvision.net.il> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi,
how can i create an ansi string in c#(not unicode)?
How can i convert a string member lets say string str="12345" to char*
s="12345" becuse the unicode "12345" is "1020304050" and i need to cinvert
it to char* in c# but i dont have pointers in c# so what can i do???

Thanks

Nov 17 '05 #2
Hi Dave,

If by char you mean an 8 bit unsigned value, you can get that using the Encoding of your choice and the GetBytes method

string s = "12345";
Encoding e = Encoding.GetEncoding("ISO-8859-1");
byte[] b = e.GetBytes(s);

If a pointer is needed, use an unsafe code block as Bob said.
A Char, as well as String, is always Unicode in C#.

http://msdn.microsoft.com/library/de...detutorial.asp
On Sat, 06 Aug 2005 23:18:59 +0200, Dave <be******@netvision.net.il> wrote:
Hi,
how can i create an ansi string in c#(not unicode)?
How can i convert a string member lets say string str="12345" to char*
s="12345" becuse the unicode "12345" is "1020304050" and i need to cinvert
it to char* in c# but i dont have pointers in c# so what can i do???

Thanks


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Salisha Khan | last post by:
I have an instance method that takes an ansi string. Dim foo As Object foo(String a) The problem is Strings in VB .NET are unicode while in order for the method to work it must accept an...
4
by: Julia | last post by:
Hi, I need to convert unicode string to ansi string Thanks in adavance.
3
by: **Developer** | last post by:
I need to paste an RTF non-ANSI string into a RichTextBox. I know how to do that if the string were all ANSI characters. But the text contains Unicode characters that have no ANSI equivalent. I...
4
by: Nick | last post by:
Hi, I am trying to output a string of chinese characters as a text file. When I open a file for writing from VB, the file is automatically set to UTF-8 encoding (can tell by opening the file...
11
by: LucaJonny | last post by:
Hi, I've got a problem using StreamReader in VB.NET. I try to read a txt file that contains extended characters and theese are removed from the line that is being read. I've read a lot of...
0
by: Edwin Knoppert | last post by:
I'm currently using a wrapper which converts an ANSI BSTR from a dll. (Yes, singlebyte but BSTR ! ) This works fine and i'm aware BSTR's returned must be destroyed by the caller, which i do. ...
7
by: Paul Connolly | last post by:
char *s = "Hello"; s = 'J'; puts(s); might print "Jello" in a pre-ANSI compiler - is the behaviour of this program undefined in any pre-ANSI compiler - or would it always have printed "Jello"...
10
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from...
6
by: msdnuniv | last post by:
Hello everybody, since days i try to convert Unicode-Strings in VB.NET to ANSI which should be processable in VB6 and converted to unicode again. It should be possible with any codepage, e.g....
0
NeoPa
by: NeoPa | last post by:
ANSI-89 v ANSI-92 Before we get into all the various types of pattern matching that can be used, there are two ANSI standards used for the main types of wildcard matching (matching zero or more...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.