如何一次在矩阵中设置一行 [英] How to Set A Row In a Matrix At Once

查看:91
本文介绍了如何一次在矩阵中设置一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


变量Source是一个字符串,例如"你好,我的名字是詹姆斯"

The variable Source is a string such as "hello, my name is James"


我使用此代码可以选择这句话中的某些单词。 

I am using this code to be able to select certain words in this sentence. 


下面的代码将arrayint作为1x2字符串数组输出,第一列是"hello"。第二个是"我的名字是詹姆斯"。  然后,代码会根据空格再次将其拆分。  我希望它的结构为[hello,
,,;我的,名字,是,James]

The code below would output arrayint as a 1x2 string array, with the first column being "hello" and the second being "my name is James".  Then, the code splits it up again based on spaces.  I want it to have the structure of [hello, , , ; my, name, is, James]


我无法弄清楚如何将列指定为我想要的列。

I cannot figure out how to assign the columns to be what I want them to.


在matlab中,我会说arr(计数器-1,1:4),设置第1列到第4列。 是否有visual basic的并行方式?

In matlab I would say arr(counter - 1, 1:4), setting columns 1 to 4.  Is there a parallel way for visual basic?

Dim arrint() As String arrint() = VBA.Split(Source, ",") Lengtharrint = UBound(arrint) + 1 Dim arr() As String For counter = 1 To Lengtharrint

arr counter - 1 ,???) = Split arrint counter - 1 ), ""
下一步

arr(counter - 1,???) = Split(arrint(counter - 1), " ") Next

推荐答案

Re:  text to an an数组

Re:  text to an array

你的叙述对我来说并不清楚;试试这个......

'---

Sub TextToArray(ByRef strSource As String)

' Jim Cone - 俄勒冈州波特兰市 - 2015年12月

  Dim arr( )作为字符串

  Dim strNew As String

  Dim vTemp As Variant

  Dim C As Long

  Dim N As Long

  Dim R As Long



  C = 4 '列地点

  R = 3 '行位置

  N = VBA.InStr(1,strSource,& ;,",vbBinaryCompare) '逗号的位置

$
 如果N> 0则则为
   strNew = VBA.Right

Your narrative is not clear to me; try this...
'---
Sub TextToArray(ByRef strSource As String)
'Jim Cone - Portland, Oregon - Dec. 2015
 Dim arr() As String
 Dim strNew As String
 Dim vTemp As Variant
 Dim C As Long
 Dim N As Long
 Dim R As Long

 C = 4  'column location
 R = 3  'row location
 N = VBA.InStr(1, strSource, ",", vbBinaryCompare)  'position of comma

 If N > 0 Then
   strNew = VBA.Right


(strSource,VBA.Len(strSource) - N)

 其他¥ b $ b   MsgBox"找不到逗号。&n bsp; ",vbExclamation," jsb348"

  退出子星号
 结束如果

  vTemp = VBA.Split(VBA.Trim(strNew),"",-1,vbBinaryCompare)



'大小数组

  ReDim arr(1到2,LBound(vTemp)到UBound(vTemp))

'加载数组的第一个元素。

  arr(1,0)= VBA.Left(strSource,N - 1)

'加载第二行数组。

  For N = LBound(vTemp)到UBound(vTemp)

   arr(2,N)= vTemp(N)

 下一个

'将数组值放在工作表上。

 范围(单元格(R,C),单元格(R + 1,UBound(vTemp)+ C))= arr()

结束子

' ---
$
Sub GetItStarted()

 调用TextToArray("你好,单个文档界面糟透了")

结束子

(strSource, VBA.Len(strSource) - N)
 Else
   MsgBox "Can't find comma.   ", vbExclamation, "jsb348"
   Exit Sub
 End If
 vTemp = VBA.Split(VBA.Trim(strNew), " ", -1, vbBinaryCompare)

'Size array
 ReDim arr(1 To 2, LBound(vTemp) To UBound(vTemp))
'Load first element of array.
  arr(1, 0) = VBA.Left(strSource, N - 1)
'Load second row of array.
 For N = LBound(vTemp) To UBound(vTemp)
   arr(2, N) = vTemp(N)
 Next
'Place array values on worksheet.
 Range(Cells(R, C), Cells(R + 1, UBound(vTemp) + C)) = arr()
End Sub
'---
Sub GetItStarted()
  Call TextToArray("hello, single document interface sucks")
End Sub
"--- ---
Jim Cone

美国俄勒冈州波特兰市
https://goo.gl/IUQUN2  (Dropbox)
'---
Jim Cone
Portland, Oregon USA
https://goo.gl/IUQUN2 (Dropbox)


这篇关于如何一次在矩阵中设置一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆