-3

char value to string in string builder in vb.net Dim ss As String = "AHKLJ47815" ' take any string

    Dim finalstring As String

    For i = 0 To ss.Length - 1
    value = AscW(ss(i))   'now take value of that char at i index in int

                If value > 100 Then
                    finalstring = "0"+ value
                Else
                    finalstring = value

                End If

    Next

now the finalstring should result the value in integer of all chars but if the value of that particular char in integer is more than 100 then keep it as it is if less then append 0 before that 2 digit integer and make final string contains the all value of chars

something like this

String = "ABCo21"

now finalstring should have = "065066067111049050

  • In what way is your code not working as expected? You have to actually explain the problem. – David Dec 27 '15 at 20:07
  • david the error is nothing actually when i provide intarray(100) space i dont get anything but i get system.int32[] something like this – androidstarter Dec 27 '15 at 20:26
  • By default the string representation of an object is the name of the object's type. There's no automatic string representation for an integer array, you'd have to build the string from the values. You can do this with something like `string.Join()` pretty easily. – David Dec 27 '15 at 20:28
  • david when i try Dim s As String s = s.Join("", value) it result only last value of char in md5 hash – androidstarter Dec 27 '15 at 20:39
  • Well, `value` is only a single integer. What do you expect that result to be if not that one single integer? It's really not clear what you're even *trying* to do at this point. – David Dec 27 '15 at 20:41
  • It's not value, rather you should provide the array variable in `Join()` method. – Rahul Dec 27 '15 at 20:43
  • hello david and rahul i have edited my question again with better i can make you understand hope you get now what i want :) – androidstarter Dec 27 '15 at 20:53

1 Answers1

1

Yes you will cause you have just declared the integer array but have not initialized it.

Dim intarr() As Integer

Should be like below and then you can use it inside your loop construction. See Documentation for more information.

Dim intarr = New Integer() {1, 2, 4, 8}

If you want to store the array element from different source then just initialized the array like

Dim intarr = New Integer(md5hash.Length) {}

Use it in your for loop

 For i = 0 To md5hash.Length - 1
                value = AscW(md5hash(i))

                If value > 132 Then
                    ' do something with value and then
                    intarr(i) = value
Rahul
  • 76,197
  • 13
  • 71
  • 125
  • hi Rahul how can i initialized the intarray because i need to take the value in array from the md5hash string and put its int value in that array – androidstarter Dec 27 '15 at 20:16
  • See edit in answer if that helps. check the MSDN link in answer to gain a better understanding. – Rahul Dec 27 '15 at 20:20
  • brother i cannot take Dim intarr = New Integer(md5hash.Length) {} cus when u convert those char to int there each char value is in 2 char in integer – androidstarter Dec 27 '15 at 20:24
  • I am not quiet sure that i have understood but if you want to store string representation of your int value then create a `string` array instead and call `ToString()` on your values while storing in array. – Rahul Dec 27 '15 at 20:30
  • i tried but it is not working try to run the code taking md5hash anything maybe you can see where i am struggling :) – androidstarter Dec 27 '15 at 20:34