Foxtable(狐表)用户栏目专家坐堂 → 如何精准截取字符(已解决)


  共有5043人关注过本帖树形打印复制链接

主题:如何精准截取字符(已解决)

帅哥哟,离线,有人找我吗?
hongye
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:437 积分:2949 威望:0 精华:0 注册:2011/3/15 12:49:00
如何精准截取字符(已解决)  发帖心情 Post By:2022/5/5 14:10:00 [只看该作者]

Dim Vu As String = "在派生类中重写时,获取当前 Encoding 的代码页标识符"
Dim s As Integer = 19
Dim Vu1 As String = Vu.SubString(0, s)
Dim c As Integer = (Vu1.Length * 2 - Encoding.default.GetBytes(Vu1).length) / 2
 Output.Show(c & "   " & Vu1 & "   " & Vu1.Length & "   " & Encoding.default.GetBytes(Vu1).length)
 Dim Vu2 As String = Vu.SubString(0, s + c)
Dim e As Integer = (Vu2.Length * 2 - Encoding.default.GetBytes(Vu2).length) / 2
Output.Show(e & "   " & Vu2 & "   " & Vu2.Length & "   " & Encoding.default.GetBytes(Vu2).length)
Dim g As Integer = e - c
Dim Vu3 As String = Vu.SubString(0, s + c + g)
Output.Show(e & "   " & Vu3 & "   " & Vu3.Length & "   " & Encoding.default.GetBytes(Vu3).length)

目的是截断第38个字节,使其在文本框中实现自动换行
这个看似可以但是有没有更简便的方法?

我使用在

        Dim Vu As String
        Dim Multi As String = s1
        Dim Values() As String
        Values = Multi.split(",")
        Dim Value As String
        For i As Integer = 0 To Values.Count - 1
            Dim sbu As New StringBuilder
            Dim c = Encoding.default.GetBytes(Values(i))
'            msgbox(c.length)
            Dim d As Double
            d = Values(i).Length*2 - c.length
'            msgbox(Values(i) & d)
            Dim sd As Double
            sd = d \ 2
'            msgbox("差数" & sd)
            If c.length > 42 Then 
                Do While Values(i).length > 20 + sd
                    sbu.AppendLine(Values(i).SubString(0, 20 + sd))
                    Values(i) = Values(i).SubString(20 + sd)
                Loop
            End If
            sbu.Append(Values(i))
            Vu = Vu & "," & sbu.ToString
        Next 
        Value = Vu.Trim(",").Replace(",", vbcrlf)
'        Output.Show(Value)
        lb14.Visible = True
        lb14.Text = "备注: " & vbcrlf & Value 'vbcrlf & s1.Replace(",", vbcrlf)
[此贴子已经被作者于2022/5/5 20:32:33编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110813 积分:564003 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/5/5 15:11:00 [只看该作者]

基本也就只能这样了

 回到顶部
帅哥哟,离线,有人找我吗?
hongye
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:437 积分:2949 威望:0 精华:0 注册:2011/3/15 12:49:00
  发帖心情 Post By:2022/5/5 20:10:00 [只看该作者]

Dim lb1 As WinForm.Label = e.Form.Controls("Label1")
Dim lb2 As WinForm.Label = e.Form.Controls("Label2")
Dim lb3 As WinForm.Label = e.Form.Controls("Label3")
Dim lb4 As WinForm.Label = e.Form.Controls("Label4")
Dim lb5 As WinForm.Label = e.Form.Controls("Label5")
Dim lb6 As WinForm.Label = e.Form.Controls("Label6")
Dim lb7 As WinForm.Label = e.Form.Controls("Label7")
Dim lb8 As WinForm.Label = e.Form.Controls("Label8")
Dim lb9 As WinForm.Label = e.Form.Controls("Label9")
Dim lb10 As WinForm.Label = e.Form.Controls("Label10")
Dim lb11 As WinForm.Label = e.Form.Controls("Label11")
Dim lb12 As WinForm.Label = e.Form.Controls("Label12")
Dim lb13 As WinForm.Label = e.Form.Controls("Label13")
Dim lb14 As WinForm.Label = e.Form.Controls("Label14")
If DataTables("窗口3_Table1").DataRows.Count = 0 Then '如果是一个空表
    Return '那么返回
Else    
    If Tables("窗口3_Table1").Current.IsNull("面料识别号") = False Then
        lb1.Text = "面料识别号: " & Tables("窗口3_Table1").Current("面料识别号")
    Else
        lb1.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("客户编号") = False Then
        lb2.Text = "客户编号: " & Tables("窗口3_Table1").Current("客户编号")
    Else
        lb2.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("面料名称") = False Then
        lb3.Text = "面料名称: " & Tables("窗口3_Table1").Current("面料名称")
    Else
        lb3.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("面料门幅") = False Then
        lb4.Text = "面料门幅: " & Tables("窗口3_Table1").Current("面料门幅") & " Cm"
    Else
        lb4.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("面料克重") = False Then
        lb5.Text = "面料克重: " & Tables("窗口3_Table1").Current("面料克重") & " g/m2"
    Else
        lb5.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("色号") = False Then
        lb6.Text = "面料色号: " & Tables("窗口3_Table1").Current("色号")
    Else
        lb6.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("颜色") = False Then
        lb7.Text = "面料颜色: " & Tables("窗口3_Table1").Current("颜色")
    Else
        lb7.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("品牌") = False Then
        lb8.Text = "品牌: " & Tables("窗口3_Table1").Current("品牌")
    Else
        lb8.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("款号") = False Then
        lb9.Text = "款号: " & Tables("窗口3_Table1").Current("款号")
    Else
        lb9.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("件数") = False Then
        lb10.Text = "件数: " & Tables("窗口3_Table1").Current("件数")
    Else
        lb10.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("数量") = False Then
        lb11.Text = "成品数量: " & Tables("窗口3_Table1").Current("数量") & " Kg" 
    Else
        lb11.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("交货日期") = False Then
        lb12.Text = "交货日期: " & Tables("窗口3_Table1").Current("交货日期")
    Else
        lb12.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("交货单位") = False Then
        lb13.Visible = True
        lb13.Text = "交货单位: " & Tables("窗口3_Table1").Current("交货单位")
    Else
        lb13.Visible = False
    End If
    Dim s1 As String = Tables("窗口3_Table1").Current("备注").Replace(", ", ",").Replace(", ", ",").Replace(" ,", ",").Replace(" ,", ",").Replace(vbcrlf, ",").Replace(vbtab, ",").Replace(" ", ",").Replace(",", ",").Replace(" ,", ",").Replace("(备注", ",(备注")  
    If s1 <> "" Then
        Dim Vu As String
        Dim Multi As String = s1
        Dim Values() As String
        Values = Multi.split(",")
        Dim Value As String
        For i As Integer = 0 To Values.Count - 1
            Dim sbu As New StringBuilder
            msgbox("1")
            Dim ite As Integer = 18
            msgbox("2")
            Dim szb As String = Values(i).SubString(0, ite)
            msgbox(szb)
            Dim c As Integer = (szb.Length * 2 - Encoding.default.GetBytes(szb).length) / 2
            msgbox(c)
            Dim szc As String = Values(i).SubString(0, ite + c)
            Dim l As Integer = (szc.Length * 2 - Encoding.default.GetBytes(szc).length) / 2
            msgbox(e)
            Dim g As Integer = l - c
            If Encoding.default.GetBytes(Values(i)).length > 42 Then 
                Do While Values(i).SubString(0, ite + c + g)
                    sbu.AppendLine(Values(i).SubString(0, ite + c + g))
                    Values(i) = Values(i).SubString(0, ite + c + g)
                Loop
            End If
            sbu.Append(Values(i))
            Vu = Vu & "," & sbu.ToString
        Next 
        Value = Vu.Trim(",").Replace(",", vbcrlf)
        lb14.Visible = True
        lb14.Text = "备注: " & vbcrlf & Value
    Else
        lb14.Visible = False
    End If
End If

图片点击可在新窗口打开查看此主题相关图片如下:01.jpg
图片点击可在新窗口打开查看

怎么回事?哪里错了?





 回到顶部
帅哥哟,离线,有人找我吗?
hongye
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:437 积分:2949 威望:0 精华:0 注册:2011/3/15 12:49:00
  发帖心情 Post By:2022/5/5 20:32:00 [只看该作者]

Dim lb1 As WinForm.Label = e.Form.Controls("Label1")
Dim lb2 As WinForm.Label = e.Form.Controls("Label2")
Dim lb3 As WinForm.Label = e.Form.Controls("Label3")
Dim lb4 As WinForm.Label = e.Form.Controls("Label4")
Dim lb5 As WinForm.Label = e.Form.Controls("Label5")
Dim lb6 As WinForm.Label = e.Form.Controls("Label6")
Dim lb7 As WinForm.Label = e.Form.Controls("Label7")
Dim lb8 As WinForm.Label = e.Form.Controls("Label8")
Dim lb9 As WinForm.Label = e.Form.Controls("Label9")
Dim lb10 As WinForm.Label = e.Form.Controls("Label10")
Dim lb11 As WinForm.Label = e.Form.Controls("Label11")
Dim lb12 As WinForm.Label = e.Form.Controls("Label12")
Dim lb13 As WinForm.Label = e.Form.Controls("Label13")
Dim lb14 As WinForm.Label = e.Form.Controls("Label14")
If DataTables("窗口3_Table1").DataRows.Count = 0 Then '如果是一个空表
    Return '那么返回
Else    
    If Tables("窗口3_Table1").Current.IsNull("面料识别号") = False Then
        lb1.Text = "面料识别号: " & Tables("窗口3_Table1").Current("面料识别号")
    Else
        lb1.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("客户编号") = False Then
        lb2.Text = "客户编号: " & Tables("窗口3_Table1").Current("客户编号")
    Else
        lb2.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("面料名称") = False Then
        lb3.Text = "面料名称: " & Tables("窗口3_Table1").Current("面料名称")
    Else
        lb3.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("面料门幅") = False Then
        lb4.Text = "面料门幅: " & Tables("窗口3_Table1").Current("面料门幅") & " Cm"
    Else
        lb4.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("面料克重") = False Then
        lb5.Text = "面料克重: " & Tables("窗口3_Table1").Current("面料克重") & " g/m2"
    Else
        lb5.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("色号") = False Then
        lb6.Text = "面料色号: " & Tables("窗口3_Table1").Current("色号")
    Else
        lb6.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("颜色") = False Then
        lb7.Text = "面料颜色: " & Tables("窗口3_Table1").Current("颜色")
    Else
        lb7.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("品牌") = False Then
        lb8.Text = "品牌: " & Tables("窗口3_Table1").Current("品牌")
    Else
        lb8.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("款号") = False Then
        lb9.Text = "款号: " & Tables("窗口3_Table1").Current("款号")
    Else
        lb9.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("件数") = False Then
        lb10.Text = "件数: " & Tables("窗口3_Table1").Current("件数")
    Else
        lb10.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("数量") = False Then
        lb11.Text = "成品数量: " & Tables("窗口3_Table1").Current("数量") & " Kg" 
    Else
        lb11.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("交货日期") = False Then
        lb12.Text = "交货日期: " & Tables("窗口3_Table1").Current("交货日期")
    Else
        lb12.Visible = False
    End If
    If Tables("窗口3_Table1").Current.IsNull("交货单位") = False Then
        lb13.Visible = True
        lb13.Text = "交货单位: " & Tables("窗口3_Table1").Current("交货单位")
    Else
        lb13.Visible = False
    End If
    Dim s1 As String = Tables("窗口3_Table1").Current("备注").Replace(", ", ",").Replace(", ", ",").Replace(" ,", ",").Replace(" ,", ",").Replace(vbcrlf, ",").Replace(vbtab, ",").Replace(" ", ",").Replace(",", ",").Replace(" ,", ",").Replace("(备注", ",(备注")  
    If s1 <> "" Then
        Dim Vu As String
        Dim Multi As String = s1
        Dim Values() As String
        Values = Multi.split(",")
        Dim Value As String
        For i As Integer = 0 To Values.Count - 1
            Dim sbu As New StringBuilder
            If Encoding.default.GetBytes(Values(i)).length > 42 Then 
                Dim ite As Integer = 21
                Dim szb As String = Values(i).SubString(0, ite)
                Dim c As Integer = (szb.Length * 2 - Encoding.default.GetBytes(szb).length) / 2
                Dim szc As String = Values(i).SubString(0, ite + c)
                Dim l As Integer = (szc.Length * 2 - Encoding.default.GetBytes(szc).length) / 2
                Dim g As Integer = l - c
                Do While Values(i).length > ite + c + g
                    sbu.AppendLine(Values(i).SubString(0, ite + c + g))
                    Values(i) = Values(i).SubString(ite + c + g)
                Loop
            End If
            sbu.Append(Values(i))
            Vu = Vu & "," & sbu.ToString
        Next 
        Value = Vu.Trim(",").Replace(",", vbcrlf)
        lb14.Visible = True
        lb14.Text = "备注: " & vbcrlf & Value
    Else
        lb14.Visible = False
    End If
End If



 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110813 积分:564003 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/5/5 20:56:00 [只看该作者]

dim srr() as string = {"面料识别号","客户编号","面料名称",....}
If DataTables("窗口3_Table1").DataRows.Count = 0 Then '如果是一个空表
    Return '那么返回
Else   
‘中间可以优化一下 
for i as integer = 0 to srr.length - 1
Dim lb1 As WinForm.Label = e.Form.Controls("Label" & (i+1))
    If Tables("窗口3_Table1").Current.IsNull(srr(i)) = False Then
        lb1.Text = srr(i) & ": " & Tables("窗口3_Table1").Current(srr(i))
    Else
        lb1.Visible = False
    End If
next
    Dim s1 As String = Tables("窗口3_Table1").Current("备注").Replace(", ", ",").Replace(", ", ",").Replace(" ,", ",").Replace(" ,", ",").Replace(vbcrlf, ",").Replace(vbtab, ",").Replace(" ", ",").Replace(",", ",").Replace(" ,", ",").Replace("(备注", ",(备注")  
    If s1 <> "" Then
……

 回到顶部