Tuesday, July 28, 2009

How to store a string in a matrix in visual basic?

Hello


I have 2 strings of characters that are on a text box on visual basic and I would like to store in a matrix bidimensional. Each character is separated by a blank space, for example if the strings are the following each one on separated lines:


M y h o u s e i s b i g


H e r h o u s e i s b i g g e r


I would like to store in matrix M each character of the string as follows:


M(1,1)=M


M(1,2)=y


M(1,3)=h


M(1,4)=0


M(1,5)=u


until the end of the phrase (or string)


and then it should go to the next line and store in a different matrix the next string as follows:


C(2,1)=H


C(2,2)=e


C(2,3)=r


C(2,4)=h


C(2,5)=o


C(2,6)=u


until the end of string


Can somebody help me to write a code in visual basic(Not visial net, pls) to solve this problem?


Thank you very much

How to store a string in a matrix in visual basic?
I suggest using split function. It returns a single dimensioned array. That is where you will need to fill in the rest because what you are showing me is some weird stuff and I dont know where you are going with it.





Example:





Dim SingleDimensionedString





SingleDimensionedString = Split("M Y H O U S E", Space(1))





'Split takes a string and a delimiter. In this case a single space character returned by Space function is the delimiter.
Reply:This might be what you're looking for:





lines=split(input,vbcrlf)


for line=0 to ubound(lines)


letters=split(lines(line)," ")


for letter=0 to ubound(letters)


matrix(line,letter)=letters(letter)


next


next





I have no idea how to format code reasonably here - sorry.


No comments:

Post a Comment