473,799 Members | 3,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

3 questions... (string related)

Hi,

I'm writing a C# Windows Application and i have 3 questions:

1. I have a string which i want to write into file but i want to write it in
ASCII format, how can i do it?

2. I need my string to be 120 chars length, incase it's less then 120 chars,
i need to fill it with spaces, is there better way to do it then:

while(str.lengt h<120)
{
str=str+" ";
}

3.I need to concatenate few string into one string, but i need to keep the
orginal order, my string contains numbers, english letters, hebrew letters
and white spaces. when i'm using str=str1+str2 the order is mixed (the hebrew
and english letters along with the numbers), is it better way to concatenate
my strings to one string that keep the order of my strings?

Thanks,
Gidi.
Nov 17 '05 #1
6 2028
Hi Gidi,

for your first question (set the encoding information):

StreamWriter sw = new StreamWriter(st ring path, true,
System.Text.Enc oding.ASCII);

for your second question (use PadRight() method):

string mystring = "Hello";
if(mystring.Len gth < 120)
mystring.PadRig ht(120, new char(' '));

For your third question, use an ArrayList and insert
the strings in the right order, after that concate
them by foreach with +=

Cheers
Lars Behrmann

_______________ __
Nothing is impossible. UML is the key for all your problems.
AODL - Make your .net apps OpenOffice ready
http://aodl.sourceforge.net/
Gidi schrieb:
Hi,

I'm writing a C# Windows Application and i have 3 questions:

1. I have a string which i want to write into file but i want to write it in
ASCII format, how can i do it?

2. I need my string to be 120 chars length, incase it's less then 120 chars,
i need to fill it with spaces, is there better way to do it then:

while(str.lengt h<120)
{
str=str+" ";
}

3.I need to concatenate few string into one string, but i need to keep the
orginal order, my string contains numbers, english letters, hebrew letters
and white spaces. when i'm using str=str1+str2 the order is mixed (the hebrew
and english letters along with the numbers), is it better way to concatenate
my strings to one string that keep the order of my strings?

Thanks,
Gidi.


Nov 17 '05 #2
"Lars Behrmann" <la***********@ web.de> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
if(mystring.Len gth < 120)
mystring.PadRig ht(120, new char(' '));


The first line is unnecessary...
Nov 17 '05 #3
> > if(mystring.Len gth < 120)
mystring.PadRig ht(120, new char(' '));


The first line is unnecessary...


And the second line should be

mystring = mystring.PadRig ht(120, ' ');
Mattias

Nov 17 '05 #4
Hi Lars,

Thanks for your fast answer.
I tried to use:
StreamWriter sw=new StreamWriter(st ring path,true,Syste m.Text.Encoding .ASCII);
and now instead of hebrew letters i see in the file ???? (before that i saw
it as gibberish), do u have any idea why?

Thanks Again,
Gidi.

"Lars Behrmann" wrote:
Hi Gidi,

for your first question (set the encoding information):

StreamWriter sw = new StreamWriter(st ring path, true,
System.Text.Enc oding.ASCII);

for your second question (use PadRight() method):

string mystring = "Hello";
if(mystring.Len gth < 120)
mystring.PadRig ht(120, new char(' '));

For your third question, use an ArrayList and insert
the strings in the right order, after that concate
them by foreach with +=

Cheers
Lars Behrmann

_______________ __
Nothing is impossible. UML is the key for all your problems.
AODL - Make your .net apps OpenOffice ready
http://aodl.sourceforge.net/
Gidi schrieb:
Hi,

I'm writing a C# Windows Application and i have 3 questions:

1. I have a string which i want to write into file but i want to write it in
ASCII format, how can i do it?

2. I need my string to be 120 chars length, incase it's less then 120 chars,
i need to fill it with spaces, is there better way to do it then:

while(str.lengt h<120)
{
str=str+" ";
}

3.I need to concatenate few string into one string, but i need to keep the
orginal order, my string contains numbers, english letters, hebrew letters
and white spaces. when i'm using str=str1+str2 the order is mixed (the hebrew
and english letters along with the numbers), is it better way to concatenate
my strings to one string that keep the order of my strings?

Thanks,
Gidi.


Nov 17 '05 #5
"Gidi" <sh*****@hotmai l.com.dontspam> wrote in message
news:00******** *************** ***********@mic rosoft.com...
StreamWriter sw=new StreamWriter(st ring
path,true,Syste m.Text.Encoding .ASCII);
and now instead of hebrew letters i see in the file ???? (before that i
saw
it as gibberish), do u have any idea why?


I wonder if it's because the Hebrew character set does not fit into the
"standard" ASCII range i.e. from 32 to 127...?
Nov 17 '05 #6
Mattias Sj?gren <Ma***********@ discussions.mic rosoft.com> wrote:
if(mystring.Len gth < 120)
mystring.PadRig ht(120, new char(' '));


The first line is unnecessary...


And the second line should be

mystring = mystring.PadRig ht(120, ' ');


Or preferrably just

mystring = mystring.PadRig ht(120);

Space is used as the default character to pad with :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7

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

Similar topics

5
2518
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to have a separate data adapter & a separate data set for each select query? If thats possible then how?
5
1313
by: Ivan Demkovitch | last post by:
Hi! I'm building my portal and I found that some times I need to dinamically generate address. Since I have many modules and each could have it's own parameters in order to preserve other's modules stuff I try to preserve Query string: string GetQueryString()
9
1312
by: eitan | last post by:
Hello, I am using Microsoft Visual Studio 2003 .NET. I have several question, please. 1) I have a connection to the database, which I create it at login, by application("conMain") (I have some problems by using session("conMain"), see question 2). I don't know if it's a good thing to do, and not oppenning at each page the
4
1855
by: Steve | last post by:
I have read a couple articles online, read my Jesse Liberty book but I am still confused as to just what the best practices are for using exceptions. I keep changing how I'm working with them and it has now, after 15k lines of code resulted in a royal mess! It's my hope to ask some specific questions with scenario examples and that some of you might offer a little guidance or general suggestions. 1) string...
0
4602
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
1
1022
by: shapper | last post by:
Hello, I am having 2 problems related with strings: 1. I have a string as follows: "File01.xml,File02.xml,File03.xml" I need to create an array where first item is "File01.xml", second item is "File02.xml", etc. 2. When having string "File01.xml" I need to get "File01" by removing ".xml"
14
4115
by: shamirza | last post by:
Question Do ActiveX DLLs made in VB still need the VB runtimes on the machine? ________________________________________ Answer In a word, Yes. Visual Basic does not support what is known as "Static
102
5559
by: dreamznatcher | last post by:
Hello, I'm considering a career switch to a more database-related job, but need help on a few questions and issues. I'm a Computer Engineering graduate and have always felt most comfortable creating database- driven applications, preferably for web portals. 1. What are the most viable career options for me out there? What profile do I fit in? 2. What is the current job market/salary situation for database
8
7988
by: Krypto | last post by:
Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying to catch up again with Python. I am now appearing for Job Interviews these days and I am wondering if anybody of you appeared for a Python Interview. Can you please share the questions you were asked. That will be great help to me.
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10214
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9067
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7561
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.