Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
convert position string in text is decimal to binary in vb.net2010 l hope to help me
example
text is:lam waersoft l will to engineering in future<
my question what is the value of position in text to all word such as;l,am and convert to this value to binary code
Posted
Comments
Prasad_Kulkarni 4-Apr-12 8:31am    
Mate, I have tried my best to understand your question. But I really cant able. Can you please make it a bit easier to understood.

Create a loop to iterate over the characters in the string. At each 'value' point display the character index in whatever number base you are interested in, so for position 12 it would look something like:
Decimal: 12
Hex:     x0C
Octal:   014
Binary:  01100
 
Share this answer
 
I am not sure I've understood your question but it looks like you want the position and the positions binary representation of each word found in a string?

If that is indeed the case something like this might work for you;

VB
Sub Main()
        Dim str As String = "I am waersoft I will to engineering in future"

        Dim word As String = String.Empty
        Dim start As Integer = 0

        For i As Integer = 0 To str.Length - 1
            Dim c As Char = str.Chars(i)
            If Char.IsWhiteSpace(c) Then
                If Not String.IsNullOrWhiteSpace(word) Then
                    Console.WriteLine("Word '{0}' found at position {1} (binary value {2})", word, start, Convert.ToString(start, 2))
                End If
                word = String.Empty
            Else
                If String.IsNullOrEmpty(word) Then start = i
                word = word + c
            End If
        Next
    End Sub


Which would print something like;

none
Word 'I' found at position 0 (binary value 0)
Word 'am' found at position 2 (binary value 10)
Word 'waersoft' found at position 5 (binary value 101)
Word 'I' found at position 14 (binary value 1110)
Word 'will' found at position 16 (binary value 10000)
Word 'to' found at position 21 (binary value 10101)
Word 'engineering' found at position 24 (binary value 11000)
Word 'in' found at position 36 (binary value 100100)


Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900