Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have strings in the list data like this:

"name=Card&value=%2a%2a%2a%2a%2a%2a%2a%2a%2a%2a%2a%2a0015",
"name=MID&value=1000"
"name=Type&value=GOODS_SERVICES"

So i get as parameter List<string> someList

need to format like this, 50 chars max length

align left (empty space) align right //so to fit in 50 chars lenght
----------------------------------------------------
name (empty space) value
Card (empty space) %2a%2a%2a%2a%2a%2a%2a%2a%2a%2a%2a%2a0015
MID (empty space) 1000
Type (empty space) GOODS_SERVICES

What I have tried:

//nothing have no ide how to do this
Posted
Updated 14-Oct-20 3:30am
Comments
F-ES Sitecore 14-Oct-20 8:22am    
Use HttpUtility.ParseQueryString to parse the individual values into a collection of name\value pairs (google how to use it if it's not obvious). Once you have that collection just construct your desired output from it. Note that no-one here is going to do all of the work for you.

You can use String's PadLeft or PadRight, String.PadLeft Method (System) | Microsoft Docs[^]
 
Share this answer
 
Comments
Member 14068594 14-Oct-20 9:16am    
Can you write me code example?
ZurdoDev 14-Oct-20 9:26am    
There are some in the example I linked to.
BillWoodruff 14-Oct-20 10:30am    
+5
study this example:

put this code in a method; put a breakpoint on the indicated line; single step through the code (use F11); observe the values being created.
string example = @"name=Card&value=%2a%2a%2a%2a%2a%2a%2a%2a%2a%2a%2a%2a0015";

string[] splitter = new string[] {"name=", "&value="};

StringBuilder sb = new StringBuilder();

// put a breakpoint here, then single step
string[] splitline = example.Split(splitter, StringSplitOptions.RemoveEmptyEntries);

sb.AppendLine($"{splitline[0]} {splitline[1]}");

string result = sb.ToString();
use a StringBuilder to avoid allocating new strings. study the String.Split method: [^], [^] and the StringBuilder class: [^]
 
Share this answer
 
Comments
Member 14068594 14-Oct-20 9:53am    
Ok this is ok but i need max with of that line to be 50 (chars)
then in result must have formatted like this (card aligned to left, then other value aligned to right) in max line range of 50 chars.

Card \\\\\\\ %2a%2a%2a%2a%2a%2a%2a%2a%2a%2a%2a%2a0015
BillWoodruff 14-Oct-20 10:01am    
So study the link ZurdoDev gave you, and pad the strings as necessary. We are here to help you learn, not to write the code for you.

It took me a minute to modify the code above to produce 50 character padded strings.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900