I wanted to create a list that had predetermined prefixes, suffixes and numbering applied to a list of items.
I created 2 PreFix boxes and 2 Suffix boxes.
I then put the results together with this code:
I then put the results into a string and trim them:
I then put in a list of items separated by \n and put the prefix before the item and the suffix after the item using this code - I also number the items 001, 002 etc:
When I copy this into an excel, the "SuffixResult" appears at the start of the next item.
So if my PreFix is Q. and MN and my Suffix is Hold and my items are Apple, Orange, Pear I get this:
001 Q. MN Apple
001 Q. MN Apple
Hold002. Q. MN Orange
002 Q. MN Orange
Hold003 Q. MN Pear
003 Q. MN Pear
Hold
You can see I am throwing around a few trims, but it doesn't seem to get rid of the '\n' from the inputNames variable.
Just wondered if anyone had encountered similar or had any knowledge to impart about how to deal with it?
I created 2 PreFix boxes and 2 Suffix boxes.
I then put the results together with this code:
C#:
List<string> prefixes = new List<string>();
List<string> suffixes = new List<string>();
for (var i = 0; i < 4; i++)
{
var controlNumber = i + 1;
if (Controls[$"Suffix{controlNumber}"].Text != "")
{
suffixes.Add(Controls[$"Suffix{controlNumber}"].Text.ToString());
}
}
C#:
string outputPrefixes = string.Join("", prefixes);
string PreFixResult = outputPrefixes.Trim('\n');
string outputSuffixes = string.Join("", suffixes);
string SuffixResult = outputSuffixes.Trim('\n');
C#:
string[] inputNames;
if (nameInputTB.Text != "")
{
inputNames = nameInputTB.Text.Split('\n');
foreach (string item in inputNames)
{
j = j + 1;
string nameResult = item.Trim('\n');
outputbox.Text += j.ToString("D3") + " " + PreFixResult + " " + nameResult;
outputbox.Text += j.ToString("D3") + " " + PreFixResult + " " + nameResult + " " + SuffixResult;
}
}
So if my PreFix is Q. and MN and my Suffix is Hold and my items are Apple, Orange, Pear I get this:
001 Q. MN Apple
001 Q. MN Apple
Hold002. Q. MN Orange
002 Q. MN Orange
Hold003 Q. MN Pear
003 Q. MN Pear
Hold
You can see I am throwing around a few trims, but it doesn't seem to get rid of the '\n' from the inputNames variable.
Just wondered if anyone had encountered similar or had any knowledge to impart about how to deal with it?
Last edited by a moderator: