Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with C# string literal

Posted on 2006-11-06
5
Medium Priority
?
2,149 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 800 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

721 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