以文本方式查看主题
- Foxtable(狐表) (http://foxtable.com/bbs/index.asp)
-- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2)
---- [分享] 考古心得 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=41510)
|
-- 作者:lsy
-- 发布时间:2013/10/21 14:49:00
-- [分享] 考古心得
近来沉醉于考古------翻看很久很久以前的【精华主题】。
挖掘出一件有价值的文物,原帖地址如下:
http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=9770&authorid=0&page=7&star=1
本人喜好通用,借花献佛,整理如下:
原字符串长度、插入字符串长度、间隔长度;原字符串、插入字符串都可以自定。
(在命令窗口,测试方便,但因为输入框自动删除空格,无法直接插入空格,可先输入“空”代替空格,代码会自动替换)
Dim str As String = "好人32326777e288啦828a88bc6d78901234567890" InputValue(str,"","请输入原字符串") Dim s As String InputValue(s,"","请输入插入字符串") Dim Int As Integer = 1 InputValue(Int,"","请输入插入间隔长度") If Int = 0 Then Return "除数不能为零" End If If str.Length Mod Int = 0 Then For i As Integer = Int To (str.Length \\ Int) * (s.Length + Int) - s.Length - 1 Step s.Length + Int str = str.Insert(i,s) Next Else For i As Integer = Int To (str.Length \\ Int) * (s.Length + Int) - s.Length Step s.Length + Int str = str.Insert(i,s) Next End If str = str.Replace("空"," ") Output.Show(str)
|
-- 作者:Bin
-- 发布时间:2013/10/21 14:53:00
--
顶一个
|
-- 作者:狐狸爸爸
-- 发布时间:2013/10/21 14:56:00
--
呵呵,顶你这个考古学家,不过下面的代码更合适一些:
Dim str As String = "好人32326777e288啦828a88bc6d78901234567890" Dim str2 As String InputValue(str,"","请输入原字符串") Dim s As String InputValue(s,"","请输入插入字符串") Dim Int As Integer = 1 InputValue(Int,"","请输入插入间隔长度") If Int = 0 Then Return "除数不能为零" End If For i As Integer = 0 To str.Length -1 If i > 0 AndAlso (i +1) Mod Int = 0 Then str2 = str2 & s End If str2 = str2 & str.Chars(i) Next output.show(str2)
[此贴子已经被作者于2013-10-21 14:57:23编辑过]
|
-- 作者:lsy
-- 发布时间:2013/10/21 14:59:00
--
以下是引用狐狸爸爸在2013-10-21 14:56:00的发言:
呵呵,顶你这个考古学家,不过下面的代码更合适一些:
Dim str As String = "好人32326777e288啦828a88bc6d78901234567890" Dim str2 As String InputValue(str,"","请输入原字符串") Dim s As String InputValue(s,"","请输入插入字符串") Dim Int As Integer = 1 InputValue(Int,"","请输入插入间隔长度") If Int = 0 Then Return "除数不能为零" End If For i As Integer = 0 To str.Length -1 If i > 0 AndAlso (i +1) Mod Int = 0 Then str2 = str2 & s End If str2 = str2 & str.Chars(i) Next output.show(str2)
[此贴子已经被作者于2013-10-21 14:57:23编辑过]
变化多端,蛮有意思。
|
-- 作者:lsy
-- 发布时间:2013/10/21 15:02:00
--
经测试,狐爸的代码,结果有误啊。
|
-- 作者:狐狸爸爸
-- 发布时间:2013/10/21 15:09:00
--
这样:
Dim str As String = "好人32326777e288啦828a88bc6d78901234567890" Dim str2 As String InputValue(str,"","请输入原字符串") Dim s As String InputValue(s,"","请输入插入字符串") Dim Int As Integer = 1 InputValue(Int,"","请输入插入间隔长度") If Int = 0 Then Return "除数不能为零" End If For i As Integer = 0 To str.Length -1 str2 = str2 & str.Chars(i) If i > 0 AndAlso (i + 1) Mod Int = 0 Then str2 = str2 & s End If Next output.show(str2)
|
-- 作者:lsy
-- 发布时间:2013/10/21 15:13:00
--
好人3ppp232ppp677ppp7e2ppp88啦ppp828pppa88pppbc6pppd78ppp901ppp234ppp567ppp890ppp
插入字符串ppp,跑到最后面了。
|
-- 作者:狐狸爸爸
-- 发布时间:2013/10/21 15:17:00
--
这样:
Dim str As String = "好人32326777e288啦828a88bc6d78901234567890" Dim str2 As String InputValue(str,"","请输入原字符串") Dim s As String InputValue(s,"","请输入插入字符串") Dim Int As Integer = 1 InputValue(Int,"","请输入插入间隔长度") If Int = 0 Then Return "除数不能为零" End If For i As Integer = 0 To str.Length -1 str2 = str2 & str.Chars(i) If i > 0 AndAlso (i + 1) Mod Int = 0 AndAlso i < str.Length -1 Then str2 = str2 & s End If Next output.show(str2)
|
-- 作者:lsy
-- 发布时间:2013/10/21 15:43:00
--
以下是引用狐狸爸爸在2013-10-21 15:17:00的发言:
这样:
Dim str As String = "好人32326777e288啦828a88bc6d78901234567890" Dim str2 As String InputValue(str,"","请输入原字符串") Dim s As String InputValue(s,"","请输入插入字符串") Dim Int As Integer = 1 InputValue(Int,"","请输入插入间隔长度") If Int = 0 Then Return "除数不能为零" End If For i As Integer = 0 To str.Length -1 str2 = str2 & str.Chars(i) If i > 0 AndAlso (i + 1) Mod Int = 0 AndAlso i < str.Length -1 Then str2 = str2 & s End If Next output.show(str2)
收藏了,谢谢。
|
-- 作者:hanxuntx
-- 发布时间:2013/10/21 16:16:00
--
lsy大师,看看我这个问题
http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=41502
|