Solved

Help with C# string literal

Posted on 2006-11-06
5
2,146 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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