Answered by:
source code

Question
-
I have a 63 character string line that contains 2 other string abc and String xyz i want to print my second string xyz after first string contain 54 characters,if it does not have 54 character provide spacing?
Example:
String abc=" "; // First 54 characters
String xyz=" "; // last 9 characters
String line = abc + xyz ;
Answers
-
If you really can't work it out for yourself then a good way to research would be to go to your local supermarket and purchase a couple of items. Study the receipt carefully. In particular see if looking at the receipt and considering the very strong hints I have been giving you about proportional fonts gives you any idea of how to proceed.
Paul Linton
- Marked as answer by Bob ShenModerator Tuesday, April 23, 2013 10:21 AM
All replies
-
-
Plz use:
line.SubString(54); //to fetch the last 9 characters.
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats -
String line = abc.PadRight(54) + xyz;
It all Happenz Sendil
- Proposed as answer by PaulLinton Tuesday, April 9, 2013 6:23 AM
- Unproposed as answer by anurag saraswat Wednesday, April 10, 2013 5:19 AM
-
thanks ...
But basically my Requirement is ... i have a string item that has two string desc and string price like this string item = " " + desc + " " + price ; when i Print the item string, sometime price alignment from right side disturbed due to change in length of characters in desc, my total string length of item is 63 and string length of desc is 53 , left 9 character for price string Suggest me the code. -
string item = string.Format(" {0,-54} {1,9}", desc, price);
It all Happenz Sendil
- Proposed as answer by PaulLinton Wednesday, April 10, 2013 4:27 AM
- Unproposed as answer by anurag saraswat Wednesday, April 10, 2013 5:19 AM
-
-
You have been given a couple of answers now. Why do you keep restating the problem? If you don't know how to implement the code you have been given then show us what you have done so far. But, please, stop stating the problem over and over again.
Paul Linton
-
-
-
const string format = "{0,0} {1,4} {2,-5}";
int i = 0;
string quantity;
string size;
string desc;
string price;
string combo;
while (i < itemprint.Length)
{
string itemsline;
quantity = returnnile(itemprint[i].QUANTITY.ToString(), 2);
size = itemprint[i].DESCRIPTION.ToString();
combo = size +" "+ desc;
price = string.Format("{0:0.00}", itemprint[i].PRICE).ToString();
itemsline = String.Format(format, quantity, combo, price) + Environment.NewLine;
Printpart5 = Printpart5 + itemsline;
i = i + 1;
}
Printpart5 = Printpart5 + Dotline + Environment.NewLine;
string test = Printpart1 + Printpart2 + Environment.NewLine + Printpart3 + Environment.NewLine + Printpart4 + Printpart5 + Printpart6 + Environment.NewLine;
byte[] byteArray = Encoding.ASCII.GetBytes(test);
MemoryStream stream = new MemoryStream(byteArray);
reader = new StreamReader(stream);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.PrintTextFileHandler);
pd.Print();
pd.Dispose();
if (reader != null)
reader.Close();
}
catch (Exception ex)
{
obj.ErrorLog(Convert.ToString(this), "callPrint", ex.Message.ToString(), String.Empty, false, Convert.ToChar("E"));
}
} -
-
I can't see any evidence that you have tried to use the answers that you have been given. You said that you tried to use the solutions given but it didn't work (hint, hint - those proposed as answers by other people are most likely to be right)
Paul Linton
-
int i = 0;
string quantity;
string size;
string desc;
string price;
string combo;
while (i < itemprint.Length)
{
string itemsline;
quantity = returnnile(itemprint[i].QUANTITY.ToString(), 2);
size = itemprint[i].DESCRIPTION.ToString();
if (size.Length == 1)
{
size = size.Replace(".", "N/A");
}
desc = itemprint[i].ORDER_DESCRIPTION.ToString();
combo = size +" "+ desc;
string temp = quantity+" "+ combo;
price = string.Format("{0:0.00}", itemprint[i].PRICE).ToString();
itemsline = temp + price.PadRight(70) + Environment.NewLine;
//itemsline = String.Format(format, quantity, combo, price) + Environment.NewLine;
//itemsline = quantity + " " + combo +" " + price + Environment.NewLine + itemprint[i].TOPPING_STRING.Replace("()", "") + Environment.NewLine;
Printpart5 = Printpart5 + itemsline;
i = i + 1;
} -
What do you think that price.PadRight(70) is going to do? This was never suggested to you, but it is a learning exercise.
Use MSDN to find out if you can't guess (you have all the clues in front of you).
Are there other changes apart from price.PadRight(70)?
Paul Linton
-
-
If ur problem is solved, plz mark answers.
Otherwises plz tell us by offering an example:
1) Ur original string.
2) What do u expect to get?
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats -
my String Print output like this
1 VG Tacos Ind VG Tacos Ind 89.00
1 Pasta Vg IT WHPas Vg 95.00
1 NVG Tacos Ind NVG TacoInd 99.00
But i want if Item Name character is increase or decrease, price place is fixed in right hand side
i want like this
1 VG Tacos Ind VG Tacos Ind 89.00
1 Pasta Vg IT WHPas Vg 95.00
1 NVG Tacos Ind NVG TacoInd 99.00
-
my string is like this
string itemsline = quantity + " " + Item Name +" " + price + Environment.NewLine;
but problem is when Item Name character is increasing then my price position is disturbed
- Edited by anurag saraswat Wednesday, April 10, 2013 5:56 AM
-
-
-
-
int i = 0;
price = string.Format("{0:0.00}", itemprint[i].PRICE).ToString();
string quantity;
string size;
string desc;
string price;
string combo;
while (i < itemprint.Length)
{
string itemsline;
quantity = returnnile(itemprint[i].QUANTITY.ToString(), 2);
size = itemprint[i].DESCRIPTION.ToString();
desc = itemprint[i].ORDER_DESCRIPTION.ToString();
combo = size +" "+ desc;
itemsline = String.Format({0,1} {1,4} {2,-5}, quantity, combo, price) + Environment.NewLine;
Printpart5 = Printpart5 + itemsline;
i = i + 1;
}- Edited by anurag saraswat Wednesday, April 10, 2013 6:16 AM
-
-
-
-
i m currently applying this {0,3} {1,-15} {2,-28}
this mean {0,3} 0 mean quantity,quantity print on 3 character count from right side
{1,-15} 1 mean combo,combo print on 15 character count from left side
{2,-28} 2 mean price, price print on 28 character count from left side
-
Here is the solution...
itemsline = String.Format({0,1} {1,-54} {2,9:0.00}, quantity, combo, price) + Environment.NewLine;
It all Happenz Sendil
- Proposed as answer by ThankfulHeart Wednesday, April 10, 2013 7:06 AM
-
-
-
-
-
It works on me quite well in Console App:
class Program { static void Main(string[] args) { Console.WriteLine( String.Format("{0,1} {1,-54} {2,9:0.00}", "1", "N/A Garlic Bread", "70.00") + Environment.NewLine); Console.WriteLine(String.Format("{0,1} {1,-54} {2,9:0.00}", "1", "VG Tacos Ind VG Tacos Ind ", "70.00") + Environment.NewLine); Console.WriteLine(String.Format("{0,1} {1,-54} {2,9:0.00}", "1", "N/A Wing", "70.00") + Environment.NewLine); } }
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats -
-
Temp=quantity + combo;
String itemsline = Temp + price + Environment.NewLine;
i found the maximum length of itemline string it is 65, and Temp string max length is 56 , Now
i think if i make a method and define String itemline maximum length=65 then check if Temp string = 56 then print Temp + Price but if Temp is not equal to 56 then it can check remaining character for 56 and add " " space to complete 56 character and then print Temp + Price.
-
-
Hi anurag,
Where did u apply these codes?
In a winForm?
Can u show us ur full codes?
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats -
Nope, that won't do it (and all you are doing is rewriting what string.Format does).
Two strings of 64 characters will print with different widths when you use a proportional font.
Try it, give one product a description of
iiiiiiiiiiiiiiiiiii
and another a description of
XXXXXXXXXXXXXXXXXXX
in both cases there are 20 characters. The second one will always print wider than the first when you use a proportional font.
Paul Linton
-
-
I applying this code on my WPF Application for printing a Bill
- Edited by anurag saraswat Wednesday, April 10, 2013 7:22 AM
-
-
-
If you really can't work it out for yourself then a good way to research would be to go to your local supermarket and purchase a couple of items. Study the receipt carefully. In particular see if looking at the receipt and considering the very strong hints I have been giving you about proportional fonts gives you any idea of how to proceed.
Paul Linton
- Marked as answer by Bob ShenModerator Tuesday, April 23, 2013 10:21 AM