拆分字符串而不是字 [英] split string not words

查看:145
本文介绍了拆分字符串而不是字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何分割句子并放上两个文本框而不分割任何单词

好​​像我只在两个文本框中潜入NINETEEN成千上万的五十个RUPEES而没有划分任何单词



i想要第一个文本框中的NINETEEN成千上万和第二个文本框中的五个RUPEES但是不要像FOURTY那样划分任何单词。



我尝试了这段代码,但它分成了几个字

how do i split sentence and put on two textboxes without split any words
as if i dived NINETEEN THOUSAND THREE HUNDRED FORTY FIVE RUPEES ONLY in two textbox without divide the any words

i want NINETEEN THOUSAND THREE HUNDRED FORTY in first textbox and FIVE RUPEES ONLY in second textbox but not divide any word like FOURTY IN FOU RTY.

I tried this code but it split the words

Dim len As Integer = Me.TextBox1.Text.Trim.Length()
        If len > 25 Then
            Me.TextBox2.Text = Me.TextBox1.Text.Substring(0, 24)
            Me.TextBox3.Text = Me.TextBox1.Text.Substring(24, len - 24)

        Else
            Me.TextBox2.Text = Me.TextBox1.Text.Trim
        End If







编辑/错字




Edited/ Typo

推荐答案

好吧你似乎试图分裂单词它的值大于25个字符,

这里是根据你的代码的逻辑

well it seems you try to split the words it the value is greater than 25 characters,
here is the logic as per your code
Dim spacepos As Integer = 0
spacepos = Me.TextBox1.Text.LastIndexOf(" ", 25)
Me.TextBox2.Text = Me.TextBox1.Text.Substring(0, spacepos)
Me.TextBox3.Text = Me.TextBox1.Text.Substring(spacepos + 1, len - spacepos - 1)
MessageBox.Show(Me.TextBox2.Text.Length())
MessageBox.Show(Me.TextBox3.Text.Length())



但是第二个文本框看起来超过25个字符以上逻辑没关系,请不要阅读以下内容




but it seems the second textbox has more than 25 characters if the above logic is okay then don't read the below one

Dim tempstring As String = Me.TextBox1.Text
While tempstring.Length > 25
    spacepos = tempstring.LastIndexOf(" ", 25)
    MessageBox.Show(tempstring.Substring(0, spacepos))
    tempstring = tempstring.Substring(spacepos + 1, tempstring.Length - spacepos - 1)
End While
MessageBox.Show(tempstring)





上面的代码将所有单词拆分为25个字符及以下



the above code splits all the word for 25 characters and below


这篇关于拆分字符串而不是字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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