Skip to content

Commit 5598bf2

Browse files
committed
Update 2024-10 - Auto trim column names for whitespace -- InspectWhitespace and FormatShowControlSymbosl.pq
1 parent ab53b6a commit 5598bf2

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

forumQuestions/pq/2024-10 - Auto trim column names for whitespace -- InspectWhitespace and FormatShowControlSymbosl.pq

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ let
1111
let return =
1212
List.Transform( columnNames, ( curName ) => [
1313
HasWhitespace = RawName <> Text.Trim( curName ),
14-
RawName = curName,
15-
Symbols = Text.FormatControlSymbols( curName ),
16-
HexSummary = "Hex: " & Text.Combine( AsHexStr, ", " ),
17-
DecSummary = "Dec: " & Text.Combine(
18-
List.Transform( Codepoints, each Text.From(_) ),
19-
", " ),
14+
RawName = curName,
15+
Symbols = Text.FormatControlSymbols( curName ),
16+
HexSummary = "Hex: " & Text.Combine( AsHexStr, ", " ),
17+
DecSummary = "Dec: " & Text.Combine( List.Transform( Codepoints, each Text.From(_)), ", " ),
2018

2119
CharList = Text.ToList( RawName ),
2220
Codepoints = List.Transform( CharList, each Character.ToNumber( _ ) ),
@@ -54,6 +52,7 @@ let
5452
newChar =
5553
if codepoint <= 0x20
5654
then Character.FromNumber( codepoint + 0x2400 )
55+
else if codepoint = 0x200d then "<ZWJ>"
5756
else char
5857
][newChar]
5958
),
@@ -64,20 +63,22 @@ let
6463

6564

6665
raw_names = Table.ColumnNames( Source ),
67-
inspected = InspectInvisibleText( raw_names ),
68-
69-
/* bonus section:
70-
you can use codepoints in powerquery strings, as literals
71-
It uses hex notation.
72-
73-
Note: It requires either 4-digits or 8-digits. So "20" has to be "0020" or "00000020"
74-
*/
75-
76-
66+
raw_names_extra = {
67+
" User(cr,lf) Names",
68+
" Has#(tab) tabs ",
69+
"#(0020) Zero-Width #(200d) Joiner Inside",
70+
Character.FromNumber(0x1b),
71+
"Escape #(001b) Sequence"
72+
},
73+
74+
inspected_columns = InspectInvisibleText( raw_names ), // from enter-data
75+
inspected = InspectInvisibleText( raw_names_extra ),// inline strings for even more special chars
76+
77+
// You can use codepoints in strings using the hex notation
7778
ExampleCodepointsInPQ = [
78-
RawStr = " ",
79-
AsInline = "#(0020)",
80-
AsCodepoint = Character.FromNumber( 32 ),
79+
RawStr = " ",
80+
AsInline = "#(0020)",
81+
AsCodepoint = Character.FromNumber( 32 ),
8182
AsCodepointFromHex = Character.FromNumber( 0x20 ),
8283

8384
// test that shows they builds the exactly identical string:

0 commit comments

Comments
 (0)