[Help]Number Count[Solved]

Posts 16–30 of 36 · Page 2 of 3
It is erasing 8302

[php]
Dim Str As String = "30363738354244432030303030303032"
Dim isSpace As Boolean
Dim finalStr As String = ""
isSpace = True
For i As Integer = 1 To Str.Length

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

If you run that, you will see the result.

Hmmm, Trying to figure out why.
Code looks "ok" to me......

I'm still confused though, don't you want the 0's at the end of the string ?
ok, solved:

We need to append the 8th and 16th character also and then add space or newline


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 += Mid(Str, i, 1)
                    finalStr += vbCrLf
                    isSpace = False
                    Continue For
                Else
                    finalStr += Mid(Str, i, 1)
                    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)
Have fun (this time for sure ) lol

@Next, he don't want 0's at the end, where ever there is empty space he needs zero there.

For example "30363738354244 030303030303032 "

He wants 0's after '44' and also at the end .... !
yah i need help adding 0s now which will help complete it.
basically the # of characters has to be a multiple of 16.
For example first line has 16 characters.
Second line has 16 characters.
Third line has only 5 characters. So there needs to be 16-5 = 11 more 0s to complete this.

For example:
30363738 35424443
20303030 30303032
30363

-- theres one problem though. those arent empty space. so MJ Lover's add zero code wont work.

so final would be:
30363738 35424443
20303030 30303032
30363000 00000000
Quote Originally Posted by ppl2pass View Post
yah i need help adding 0s now which will help complete it.
basically the # of characters has to be a multiple of 16.
For example first line has 16 characters.
Second line has 16 characters.
Third line has only 5 characters. So there needs to be 16-5 = 11 more 0s to complete this.

For example:
30363738 35424443
20303030 30303032
30363

-- theres one problem though. those arent empty space. so MJ Lover's add zero code wont work.

so final would be:
30363738 35424443
20303030 30303032
30363000 00000000
If they aren't empty spaces then what are they ??? What you want to replace then ... ?
Quote Originally Posted by ppl2pass View Post
yah i need help adding 0s now which will help complete it.
basically the # of characters has to be a multiple of 16.
For example first line has 16 characters.
Second line has 16 characters.
Third line has only 5 characters. So there needs to be 16-5 = 11 more 0s to complete this.

For example:
30363738 35424443
20303030 30303032
30363

-- theres one problem though. those arent empty space. so MJ Lover's add zero code wont work.

so final would be:
30363738 35424443
20303030 30303032
30363000 00000000
Oh I see, ok done:

[php]Dim Str As String = "3036373835424443203030303030303247475"
Dim isSpace As Boolean = False
Dim finalStr As String = ""
Dim numberofLines As Integer = 3
Dim multipleOf As Integer = 16
If Str.Length < numberofLines * multipleOf Then
For i As Integer = Str.Length To (numberofLines * multipleOf) - 1
Str += "0"
Next
End If
For i As Integer = 1 To Str.Length
If i Mod 8 = 0 Then
If isSpace Then
finalStr += Mid(Str, i, 1)
finalStr += vbCrLf
isSpace = False
Continue For
Else
finalStr += Mid(Str, i, 1)
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)
[/php]

I am not gonna say have fun this time .. lol
He doesn't want to replace anything he wants to add 0's if there aren't 16 numbers.
That's what I though

But to make it easier we can pass to fill, is there a static (set) ammount of places or will it be different each time. ?
There you go , ha

Nice job MJ
thanks MJ. I added you on msn.

btw is there a way to detect the # of lines so you dont have to specify the number of lines.
Quote Originally Posted by ppl2pass View Post
thanks MJ. I added you on msn.

btw is there a way to detect the # of lines so you dont have to specify the number of lines.
This might help you, YouTube - visual basic read line
for example sometimes the code is this: and it only needs 11 more 0s to finish the line.
but for MJ's code you have to pick a specific # of lines. If i pick two this is what happens.

30363738 35424443
20303000 00000000

If i pick three: this is what happens.
30363738 35424443
20303000 00000000
00000000 00000000
It's hard to predict, though possible, I suggest you stick with a specific char count,
Why would the char count be different, what are you using this for?
i have an idea.
if # of characters is between 0 and 16 add enough 0s to complete 16 characters.
if # of characters is between 17 and 32 add enough 0s to complete 32 characters.
if # of character is between 33 and 48 add enough 0s to complete 48 characters.
Try this

[php]
Dim Str As String = "303637383542444320303030303030332423443456754 32"
Dim multipleOf As Integer
If Str.Count >= 0 <= 16 Then

multipleOf = 16
ElseIf Str.Count >= 17 <= 32 Then
multipleOf = 32
ElseIf Str.Count >= 33 <= 48 Then
multipleOf = 48
End If

Dim isSpace As Boolean = False
Dim finalStr As String = ""
Dim numberofLines As Integer = 3
If Str.Length < numberofLines * multipleOf Then
For i As Integer = Str.Length To (numberofLines * multipleOf) - 1
Str += "0"
Next
End If
For i As Integer = 1 To Str.Length
If i Mod 8 = 0 Then
If isSpace Then
finalStr += Mid(Str, i, 1)
finalStr += vbCrLf
isSpace = False
Continue For
Else
finalStr += Mid(Str, i, 1)
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)
[/php]
Edit: Code Correction

I didn't count the string, but check for me

If i did that right, there should be 47 characters and it should add 1 zero

yah it works for only 47 characters.

if there are 12 characters it still adds alot of 0s to complete 3 lines.

cause in the code.
Dim numberofLines As Integer = 3
Posts 16–30 of 36 · Page 2 of 3
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us