Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27409

VS 2019 [RESOLVED] Align strings in columns of different sizes

$
0
0
Hello!
The idea would be to get this output with the same format, these strings comes from a dictionary, the key is a string and the value a number.
Code:

SFX_BASKET_SURPRISE 0x0000073D
SFX_BASKET_TAKEHIT  0x00000067
SFX_BASKET_TALK    0x00000710
SFX_BASKET_WALK_L  0x00000068
SFX_BASKET_WALK_R  0x00000069
SFX_CS_ABY_CNCL_KNOCK            0x0000006A
SFX_CS_AKA_BATS    0x0000006B
SFX_CS_AKA_DROP_ANKH              0x0000006C
SFX_CS_AKA_END_VORTEX            0x0000006D
SFX_CS_AKA_END_VORTEX_STOP        0x00000781
SFX_CS_AKA_ISHKA_TRANSFORM1      0x0000006E
SFX_CS_AKA_ISHKA_TRANSFORM2      0x0000006F
SFX_CS_CP_BOSS_BEAM_START        0x00000070
SFX_CS_CP_BOSS_BODY_SLAM          0x00000071
SFX_CS_CP_BOSS_CROWN_APPEAR      0x00000072
SFX_CS_CP_BOSS_FLASH              0x00000073
SFX_CS_CP_BOSS_TRAN_BUILD        0x00000074
SFX_CS_CP_BOSS_TRANSFORM          0x00000075
SFX_CS_CP_FORTUNE_END            0x000007AC
SFX_CS_CP_FORTUNE_SWIRL          0x00000076
SFX_CS_DISTANT_UWATER_EXPLOSION  0x00000077
SFX_CS_HEL_ANUBIS_BEAM            0x00000078
SFX_CS_HEL_ANUBIS_EYES            0x00000079
SFX_CS_HEL_BOAT_WASH_AND_SAIL_LOOP              0x000006E5
SFX_CS_HEL_CROWN_LOOP            0x0000007A
SFX_CS_HEL_CROWN_STOP            0x0000007B
SFX_CS_HEL_IMH_MAGIC              0x00000786
SFX_CS_HEL_SPACE_AMBIENCE        0x0000007C
SFX_CS_HEL_SPACE_TUNNEL_LOOP      0x0000007D
SFX_CS_HEL_SPACE_TUNNEL_STOP      0x0000007E
SFX_CS_IMPULSE_BUMPS              0x0000007F

Using this code I get the output in the same format, but there's a problem:
Code:

Friend Sub WriteHashCode(sw As StreamWriter, Label As String, HashCode As String)
        If Len(Label) < 20 Then
                sw.WriteLine(String.Format("{0,-19} {1,8}", Label, HashCode))
        ElseIf Len(Label) < 34 Then
                sw.WriteLine(String.Format("{0,-33} {1,8}", Label, HashCode))
        ElseIf Len(Label) < 48 Then
                sw.WriteLine(String.Format("{0,-47} {1,8}", Label, HashCode))
        ElseIf Len(Label) < 62 Then
                sw.WriteLine(String.Format("{0,-61} {1,8}", Label, HashCode))
        Else
                sw.WriteLine(String.Format("{0,-75} {1,8}", Label, HashCode))
        End If
End Sub

I had to specify manually each case (if string length is less than 20, 34 etc..), there is not a max length limit, this means that this function would have to print a string with a length greater than 80 or 90.
There's a way to improve this code to get the same output without having to specify each case?

Viewing all articles
Browse latest Browse all 27409

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>