Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2005

Tip: Looking for answers? Try searching our database.

A String Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
小安 - 04 Dec 2005 03:57 GMT
void myfunction(String * Parameter){
  String* test0 = S"A";  // Parameter is also "A",but its details is not
very clear.

  String *test1 = String::Format(S"head{0}tail",test0);
  // the test1 is "headAtail"
  String *test2 = String::Format(S"head{0}tail",Parameter);
  // the test2 is "headA" , the charactors following A are all cut.}

I guess the Parameter has a terminative '\0' ,but I am not quite sure of
that.(The Watch Pannel shows that it is just a "A");
What 's the possible reason of this? How to avoid it?
Jon Skeet [C# MVP] - 04 Dec 2005 07:22 GMT
<=?Utf-8?B?5bCP5a6J?= <@discussions.microsoft.com>> wrote:
> void myfunction(String * Parameter){
>    String* test0 = S"A";  // Parameter is also "A",but its details is not
[quoted text clipped - 8 lines]
> that.(The Watch Pannel shows that it is just a "A");
> What 's the possible reason of this? How to avoid it?

I suspect you'll find that test2 is *actually* headA\0tail, but that
what you're using to display it is stopping as soon as it sees a \0.
The best fix for this is to try to work out why you're getting a \0 in
the first place, and avoid it. Otherwise, you can use String.Trim,
passing in \0 as the character to trim.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

小安 - 04 Dec 2005 11:49 GMT
Thank you!!


  TrimEnd(S"\0"->ToCharArray()) can solve the problem.

“Jon Skeet [C# MVP]”编写:

>  <=?Utf-8?B?5bCP5a6J?= <@discussions.microsoft.com>> wrote:
> > void myfunction(String * Parameter){
[quoted text clipped - 15 lines]
> the first place, and avoid it. Otherwise, you can use String.Trim,
> passing in \0 as the character to trim.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.