Foxtable(狐表)用户栏目专家坐堂 → [求助]字符串叠加


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

主题:[求助]字符串叠加

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


加好友 发短信
等级:五尾狐 帖子:1139 积分:11245 威望:0 精华:0 注册:2017/9/26 16:30:00
[求助]字符串叠加  发帖心情 Post By:2020/1/31 11:25:00 [只看该作者]

蓝老师好!
我想在每次叠加字符串时,添加一个标记行,放在字符串的首行。但是下面的代码把标记行添加到字符串的末尾了,这个代码应该怎样写?
谢谢!

......
str & = vbcrlf & "★★★" & kh & vbcrlf

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


加好友 发短信
等级:超级版主 帖子:107440 积分:546479 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/1/31 11:29:00 [只看该作者]

str =  "★★★" & kh vbcrlf & str 

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


加好友 发短信
等级:五尾狐 帖子:1139 积分:11245 威望:0 精华:0 注册:2017/9/26 16:30:00
  发帖心情 Post By:2020/1/31 12:38:00 [只看该作者]

放入批量文字识别的代码中,标记行集中到最终结果的最前面了(共识别4张图片),应该是在每一页的最前面。
老师帮忙看看是什么原因?

'''
Dim dlg As New OpenFileDialog
dlg.MultiSelect = True
dlg.Filter= "图形文件|*.bmp;*.jpg;*.gif,;*.png"
If dlg.ShowDialog = DialogResult.OK Then
    
    Dim txt As WinForm.TextBox = e.Form.Controls("TextBox1")
    Dim pic1 As WinForm.PictureBox = e.Form.Controls("PictureBox1")
    Dim str As String
    
    For Each fl As String In dlg.FileNames
        pic1.ImageFile = fl
        Dim kh As String = FileSys.GetName(fl).split(".")(0)   '取文件名
        try
            Dim client As new Baidu.Aip.Ocr.Ocr(Vars("APIKey"), Vars("SecretKey"))   '初始化接口类,传入创建的应用的API Key,Secret Key
            client.Timeout = 60000    '设置超时时间
            Dim data() As Byte = System.IO.File.ReadAllBytes(fl)   '把图片文件字节流加载进来,
            Dim options As new Dictionary(of String, object)   '使用字典传递参数
            options.Add("detect_direction","true")   '是否检测图像朝向,默认不检测
            options.Add("probability","true")
            Dim result = client.GeneralBasic(data, options)   '调用接口开始识别,返回值为JObject对象
            If result("error_code") IsNot Nothing AndAlso result("error_code") <> 0 Then
                txt.text = "识别失败: " & vbcrlf & result("error_msg").Tostring
            Else
                Dim ja As JArray = result("words_result")
                For i As Integer = 0 To ja.Count - 1
                    str = str & vbcrlf & ja(i)("words").Tostring
                Next
            End If
            str =  "★★★" & kh & vbcrlf & str    '每张图片添加图片名称
        catch ex As exception
            txt.text = str & vbcrlf & "识别接口调用失败,错误描述: " &  vbcrlf & ex.message
        End try
    Next
    txt.text =  str
End If


图片点击可在新窗口打开查看此主题相关图片如下:tt截图未命名.bmp
图片点击可在新窗口打开查看


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


加好友 发短信
等级:超级版主 帖子:107440 积分:546479 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/1/31 13:09:00 [只看该作者]

        try
str = str & vbcrlf & "★★★" & kh
            Dim client As new Baidu.Aip.Ocr.Ocr(Vars("APIKey"), Vars("SecretKey"))   '初始化接口类,传入创建的应用的API Key,Secret Key
            client.Timeout = 60000    '设置超时时间
            Dim data() As Byte = System.IO.File.ReadAllBytes(fl)   '把图片文件字节流加载进来,
            Dim options As new Dictionary(of String, object)   '使用字典传递参数
            options.Add("detect_direction","true")   '是否检测图像朝向,默认不检测
            options.Add("probability","true")
            Dim result = client.GeneralBasic(data, options)   '调用接口开始识别,返回值为JObject对象
            If result("error_code") IsNot Nothing AndAlso result("error_code") <> 0 Then
                txt.text = "识别失败: " & vbcrlf & result("error_msg").Tostring
            Else
                Dim ja As JArray = result("words_result")
                For i As Integer = 0 To ja.Count - 1
                    str = str & vbcrlf & ja(i)("words").Tostring
                Next
            End If
        catch ex As exception
            txt.text = str & vbcrlf & "识别接口调用失败,错误描述: " &  vbcrlf & ex.message
        End try

 回到顶部