TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Vaibhav Singh
NA
132
22.6k
Managing Spaces in String for Clean Output
Jan 9 2019 12:02 PM
Lets go into slowly.
Lets suppose I am building a SQL Query by actually hardcoding the syntax in code and taking parameter values for database..
The Code looks something like below
What I want now is to show output like below which should be perfectly aligned in a single line as highlighted by Yellow Line
I tried storing the contents in left in string a and contents in right in string b.
Further I used string.format something like below but that didn't work out.
That actually removes the spaces
string alignedtext = string.Format("{0,-10} | {1,5}", a,b);
So what is the best way to manage spaces such that the output looks neat and clean.
Code is below
if
(attribute_unique_index_ind ==
"False"
)
{
// table script
strb_table_script.Append(
"\t,["
+ attribute_name +
"]"
+
" "
+ attribute_datatype + attribute_precision_value +
" "
+ attribute_not_nullable);
if
(j + 1 < dv_entity_metadata.Count)
strb_table_script.Append(Environment.NewLine);
if
(attribute_datatype ==
"VARCHAR"
)
changemetxt =
"'Change Me'"
;
else
if
(attribute_datatype ==
"DATE"
)
changemetxt =
"'01/02/3456'"
;
else
changemetxt =
"'Change Me'"
;
string
a = Environment.NewLine +
"\t,"
+ changemetxt +
"AS"
+
" ["
+ attribute_name +
"]"
;
string
b =
"/*"
+ attribute_not_nullable +
"|"
+ attribute_datatype + attribute_precision_value +
"< --- UPDATE */"
;
string
alignedtext =
string
.Format(
"{0,-10} | {1,5}"
, a,b);
strb_sp_custom_block_script.Append(alignedtext);
}
Reply
Answers (
1
)
Export lakhs of records to excel from sql server table
Save upload file to server after clicking of save