A Azhar Active Member Licensed User Longtime User Sep 27, 2019 #1 Hello, It's a simple question, but I can't find the answer in the forum. I have a listView that I need to populate line by line with four columns of string data fields. To have them all aligned up visually (due to various lengths of data in the individual fields) is proving difficult. Is there a way in which I can concatenate the four fields into a format such that it will force the lengths of each data string field Eg. Format.string("#######",strOne; "###",strTwo; "####",strThree; "###",strFour) so that they all line up vertically? So here, strOne will be padded to 6 characters in length, strTwo to 3 characters in length etc Thanks, Azhar
Hello, It's a simple question, but I can't find the answer in the forum. I have a listView that I need to populate line by line with four columns of string data fields. To have them all aligned up visually (due to various lengths of data in the individual fields) is proving difficult. Is there a way in which I can concatenate the four fields into a format such that it will force the lengths of each data string field Eg. Format.string("#######",strOne; "###",strTwo; "####",strThree; "###",strFour) so that they all line up vertically? So here, strOne will be padded to 6 characters in length, strTwo to 3 characters in length etc Thanks, Azhar
E emexes Expert Licensed User Longtime User Sep 27, 2019 #2 Azhar said: Is there a way in which I can concatenate the four fields into a format such that it will force the lengths of each data string field Eg. Format.string("#######",strOne; "###",strTwo; "####",strThree; "###",strFour) so that they all line up vertically? Click to expand... Yes. There are a few String libraries that have functions like LSET or PadLeft or similar, and I have a recollection that the SmartString variable substitution has some optional formatting extensions, or... you can just use standard string concatenation ("&") and substring functions so that you know precisely what is going on, eg, what if the string is too large for the field? Probably easiest done via a function eg: Code: Copy Sub LSET(S As String, L as Int) As String Do While S.Length < L S = S & " " Loop Return S.SubString2(0, L) End Sub Log(LSET(strOne, 7) & LSET(strTwo, 3) & LSET(strThree, 4) & LSET(strFour, 3)) but you can do it inline too: Code: Copy Log((strOne & " ").SubString2(0, 7) & (strTwo & " ").SubString2(0, 3) & (strThree & " ").SubString2(0, 4) & (strFour & " ").SubString2(0, 3)) although I would probably simplify that to: Code: Copy Dim LogLine As String = "" LogLine = LogLine & (strOne & " ").SubString2(0, 7) LogLine = LogLine & (strTwo & " " ).SubString2(0, 3) LogLine = LogLine & (strThree & " " ).SubString2(0, 4) LogLine = LogLine & (strFour & " " ).SubString2(0, 3) Log(LogLine) Last edited: Sep 27, 2019 Upvote 0
Azhar said: Is there a way in which I can concatenate the four fields into a format such that it will force the lengths of each data string field Eg. Format.string("#######",strOne; "###",strTwo; "####",strThree; "###",strFour) so that they all line up vertically? Click to expand... Yes. There are a few String libraries that have functions like LSET or PadLeft or similar, and I have a recollection that the SmartString variable substitution has some optional formatting extensions, or... you can just use standard string concatenation ("&") and substring functions so that you know precisely what is going on, eg, what if the string is too large for the field? Probably easiest done via a function eg: Code: Copy Sub LSET(S As String, L as Int) As String Do While S.Length < L S = S & " " Loop Return S.SubString2(0, L) End Sub Log(LSET(strOne, 7) & LSET(strTwo, 3) & LSET(strThree, 4) & LSET(strFour, 3)) but you can do it inline too: Code: Copy Log((strOne & " ").SubString2(0, 7) & (strTwo & " ").SubString2(0, 3) & (strThree & " ").SubString2(0, 4) & (strFour & " ").SubString2(0, 3)) although I would probably simplify that to: Code: Copy Dim LogLine As String = "" LogLine = LogLine & (strOne & " ").SubString2(0, 7) LogLine = LogLine & (strTwo & " " ).SubString2(0, 3) LogLine = LogLine & (strThree & " " ).SubString2(0, 4) LogLine = LogLine & (strFour & " " ).SubString2(0, 3) Log(LogLine)
E emexes Expert Licensed User Longtime User Sep 27, 2019 #3 Azhar said: all aligned up visually ... force the lengths of each data string field Click to expand... Bear in mind that you'll need to use a monospace font eg Courier (cf NOT a proportional font eg Arial etc). Also, probably better to include an explicit space between columns, otherwise fields that are full (ie, length >= column width) will butt up against each other. Upvote 0
Azhar said: all aligned up visually ... force the lengths of each data string field Click to expand... Bear in mind that you'll need to use a monospace font eg Courier (cf NOT a proportional font eg Arial etc). Also, probably better to include an explicit space between columns, otherwise fields that are full (ie, length >= column width) will butt up against each other.
A Azhar Active Member Licensed User Longtime User Sep 27, 2019 #4 Thank you emexes. I shall try this now. Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Sep 27, 2019 #5 Don't use ListView at all. Use xCLV instead. If you want to create a table then you can use B4XTable or FlexibleTable. If you want it to be all text then check BCTextEngine: Upvote 0
Don't use ListView at all. Use xCLV instead. If you want to create a table then you can use B4XTable or FlexibleTable. If you want it to be all text then check BCTextEngine: