[Help]Number Count[Solved]

Posts 1–15 of 36 · Page 1 of 3
[Help]Number Count[Solved]
For example if I write:

ppl2pass - there are 8 characters.

71323 - there are 5 characters.

How can i count the number of characters in vb.net?
Dim s as string = "ppl2pass"
msgbox(s.length)
[php]Msgbox(textbox1.text.length) [/php]
ok it worked. ty

How bout if you want to place a space after 8 characters and a new line after 16 characters.

Original Line is this:
3036373835424443203030303030303230

This is final line.
30363738 354244432
03030303 030303230
Quote Originally Posted by ppl2pass View Post
ok it worked. ty

How bout if you want to place a space after 8 characters and a new line after 16 characters.

Original Line is this:
3036373835424443203030303030303230

This is final line.
30363738 354244432
03030303 030303230
Here you go buddy:

Code:
Dim Str As String = "30363738354244432030303030303032"
        Dim isSpace As Boolean = False
        Dim finalStr As String = ""
        For i As Integer = 1 To Str.Length

            If i Mod 8 = 0 Then
                If isSpace Then
                    finalStr += vbCrLf
                    isSpace = False
                    Continue For
                Else
                    finalStr += " "
                    isSpace = True
                    Continue For
                End If
            Else
                finalStr += Mid(Str, i, 1)
            End If
        Next
        MsgBox(finalStr)
Have Fun !!
tyvm. one more favour to ask.

if number of character is only 19 (just a random number), like this.

30363738 354244432
030

It will fill the empty space with 0s.
Like this

30363738 354244432
03000000 00000000
Quote Originally Posted by ppl2pass View Post
tyvm. one more favour to ask.

if number of character is only 19 (just a random number), like this.

30363738 354244432
030

It will fill the empty space with 0s.
Like this

30363738 354244432
03000000 00000000
Code:
Dim Str As String = "30363738354244432030303030303032"
        Dim isSpace As Boolean = False
        Dim finalStr As String = ""
        For i As Integer = 1 To Str.Length

            If i Mod 8 = 0 Then
                If isSpace Then
                    finalStr += vbCrLf
                    isSpace = False
                    Continue For
                Else
                    finalStr += " "
                    isSpace = True
                    Continue For
                End If
            Else
if Mid(Str, i, 1)=" "

                finalStr += "0"
Else
 finalstr+ = Mid(Str, i, 1)
            End If
        Next
        MsgBox(finalStr)
Done
sorry it doesnt work.

also there is an error.

with else.

i fixed it but it still doesnt add 0s.

Code:
   Dim Str As String = Label1.Text
        Dim isSpace As Boolean = False
        Dim finalStr As String = ""
        For i As Integer = 1 To Str.Length

            If i Mod 8 = 0 Then
                If isSpace Then
                    finalStr += vbCrLf
                    isSpace = False
                    Continue For
                Else
                    finalStr += " "
                    isSpace = True
                    Continue For
                End If
            Else
                If Mid(Str, i, 1) = " " Then

                    finalStr += "0"
                Else
                    finalStr += Mid(Str, i, 1)
                End If
            End If
               Next

        MsgBox(finalStr)
Over Kill Guys, Complex Methods for easy string manipulation


[php]
'Declares FinalStr as a string = to the text of label1
Dim finalStr As String = Label1.text
' Trims the first space and last space
'FinalStr = FinalStr .Trim(" ")
'Replaces the remaining spaces with 0
FinalStr = FinalStr.Replace(" ", "0")
' for testing ,displays the new string
MsgBox( FinalStr )
[/php]

I commented out the Trim, don't use it if you are intending on adding X ammount of zero's after the numbers


how would you implement it to MJLover's code?

btw i dont think ur code will work.
If i had

12345678 12345678

It wil remove the space from between.
Your right, So maybe I misunderstood, what is it you re doing excatly, I thought you said you would have something like

"234 "
and wanted 0 in the empty space

Explain, sorry
so im turning a string to hex first.
For example the string is: hhkhkjhkjh
Hex value is then: 686868485864989879878797 (i just made that up..)

I take the hex value.
Split the numbers apart every other 8 characters and new line every 16 characters.
So it would be:

68686848 58649898
79878797

But there are empty spaces there.
68686848 58649898
79878797 00000000

So i want to replace the empty spaces with 0s.


If a hex value is: 209138203981230981309
then it would be:
20913820 39812309
81309000 00000000
its not solved yet. there is a flw in MJ Lover`s code. it earses the 7th number and last number.
Quote Originally Posted by ppl2pass View Post
its not solved yet. there is a flw in MJ Lover`s code. it earses the 7th number and last number.
The code is perfectly fine for me dear. I think you messed up with Else statement. Tell me what are you inputting exactly (Don't make up, give a practical example), and I will test and give you the code !!!
Ok when i use your code:

Code:
Dim Str As String = "30363738354244432030303030303032"
        Dim isSpace As Boolean = False
        Dim finalStr As String = ""
        For i As Integer = 1 To Str.Length

            If i Mod 8 = 0 Then
                If isSpace Then
                    finalStr += vbCrLf
                    isSpace = False
                    Continue For
                Else
                    finalStr += " "
                    isSpace = True
                    Continue For
                End If
            Else
                finalStr += Mid(Str, i, 1)
            End If
        Next
        MsgBox(finalStr)
You have the string = 30363738354244432030303030303032
When i use your code it gives me:
3036373 3542444
2030303 3030303

while it should really give you this:
30363738 35424443
20303030 30303032
Posts 1–15 of 36 · Page 1 of 3
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us