取消
显示结果 
搜索替代 
您的意思是: 

insert space character between every two character in a string

已解决!
转到解答

Hello,

 

I am trying to put a space between every two characters in an input string.  I only got the VI to work after the first 2 characters.  Can you help me get the space after every two (2) characters?

 

Thanks,

hiNi

0 项奖励
1 条消息(共 19 条)
11,743 次查看

Your input looks suspiciously like a hexadecimal number. Are you sure you need to be passing around strings instead of numbers?

If you really do need to work with strings, why not keep it as strings instead of converting down to bytes?

 

 

0 项奖励
2 条消息(共 19 条)
11,735 次查看
3 条消息(共 19 条)
11,725 次查看
解答
接受人 hiNI

I was thinking more like this

破坏者
string_space.png

There's an extra space at the end which can easily be deleted.

 

4 条消息(共 19 条)
11,714 次查看
解答
接受人 hiNI

Easyer with string functions.

 

space 2 char.png

 

Ben64

5 条消息(共 19 条)
11,703 次查看

AddStringSpaces.png

 

Using \V (not vertical whitespace) adds the spaces line by line and ignores the linefeeds.

6 条消息(共 19 条)
11,669 次查看

You can get a little more performance (>10x?) if you don't use build array in a loop and avoid regex

 

Insert spaces_BD.png

0 项奖励
7 条消息(共 19 条)
11,570 次查看

@igagne wrote:

You can get a little more performance (>10x?) if you don't use build array in a loop and avoid regex

 

Insert spaces_BD.png


You will need to pad an extra space at the end of the original string is its lenght is odd.

 

Ben64

0 项奖励
8 条消息(共 19 条)
11,560 次查看

@ben64 wrote:

@igagne wrote:

You can get a little more performance (>10x?) if you don't use build array in a loop and avoid regex

 

Insert spaces_BD.png


You will need to pad an extra space at the end of the original string is its lenght is odd.

 

Ben64


Depends on what's in the requirements doc 眨眼表情

0 项奖励
9 条消息(共 19 条)
11,555 次查看

Just to break the monotony, here's yet another possibility.... 😄

 

 

 

(of course tweaks might be needed if the number of input characters is not even or if the last space is unwanted, for example)

 

 

 

10 条消息(共 19 条)
11,526 次查看