如何获取字符串中的第一个数字和第二个数字?

时间:2018-12-09 13:42:24

标签: vb.net

字符串是“ 8乘以2?”

如何获得第一个第一个数字“ 8”和第二个数字“ 2”? 我想要的是获得第一个数字,并使用要求第二个数字的数学运算。

const TaskuserSchema = new mongoose.Schema({
task_name:{
    type: String,
    required: true,
    minlength: 1,
    unique: true,
},
userId: {
    type: mongoose.Schema.Types.ObjectId,
    required: true,
  },
task_category: {
    type : String,
    required : true,
},
task_xpreward: {
    type : Number,
    required : true,
},
task_completed: {
    type : Boolean,
    required : true,
},
task_difficulty: {
    type : Number,
    required : true,
},                     //1 = Easy, 2 = Medium, 3 = Hard, 4 = Very Hard, 5 = Impossible
task_city : {
    type : String,
    required : true,
},
task_solution : String //Oplossing van de task, API gaat hierop checken
});

我尝试使用它,但是我只得到第二个数字“ 2”

1 个答案:

答案 0 :(得分:0)

    Dim str As String = "What is 8666 multiplied by 2444"
    Dim numbers As New List(Of Integer)

    For Each word As String In str.Split(" ")
        If IsNumeric(word) Then
            numbers .Add(CInt(word))
        End If
    Next

    MsgBox("first:" & numbers (0) & ",second:" & numbers (1))