Solved

Help with C# string literal

Posted on 2006-11-06
5
2,140 Views
Last Modified: 2008-01-09
Can anybody give me a quick run down of what this does;


header[header.Count - 1] += oneLine.TrimStart(new char[] {' ' /* dangerous ! */, '\t'});

I'm trying to convert an implementation of domainKeys to vb.net and I have no idea what is going on here. I get that on eof the param array is a tab - but what is going on before that?

It's only the TrimStart call I don't understand. What is going on?
0
Comment
Question by:thefritterfatboy
5 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17881545
The string stored in the last position in the array called header is having another string (oneLine) appended to it but only after any leading spaces or tabs have been trimmed off it.

TrimStart() will remove whitespace characters from the start of a string.
TrimStart(char[]) will remove any characters in the char[].
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 200 total points
ID: 17881553
for some reason someone has decided that trimming leading spaces is dangerous and had addeed a comment to that effect.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17881574
TrimStart(new char[] {' ', '\t'});

Result is string instance without leading spaces and tabs in original string. This means, if oneLine string contains any number of spaces and tabs in any order in the beginning, they are removed from result. BTW, I don't see anything dangerous here. For example , if oneLine is "   abc", this is executed as:

header[header.Count - 1] += "abc";

0
 
LVL 13

Expert Comment

by:joechina
ID: 17881625
Difference between
TrimStart(new char[] {' ', '\t'});
and
Trim();

is

Trim will remove new line and return as well

Try

string s = @"



aaa";

Console.WriteLine(s.Trim());

Console.WriteLine(s.TrimStart(new char[] {' ', '\t'}));

You will see the difference.

0
 
LVL 10

Author Comment

by:thefritterfatboy
ID: 17882305
It was the comment that had me there. I wasn't aware C# allowed for inline comments.

... I suspect the "danger" is to do with how the string is used in the encryption further down the script.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now