---
title: "格式化输出(字符串到数)"
author: "googya"
date: "2009-12-31T11:05:21Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-01-02T11:02:53Z"
id: 560295
url: "https://googya.iteye.com/blog/560295"
---

很简单的一个练习，主要是将字符串转换为数组，然后添加一些其他的东西，最后输出,格式为xxxx-xxxx-xxxx-xxxxx-xxxxx。记录一下，以免日后忘记了！




```Ruby

require "MD5"
b=Digest::MD5.hexdigest("wher is my lover?").upcase
#p
c=b.split("")
c.each_with_index do |i,j|
  print i
  if(j+1)%4==0#四个作为一节输出
    print "-" unless (j+1)==c.size
  end
end
print "\n"


```


很简单吧，可是当时由于忘记了一些方法，搞了半天才弄出来，真是郁闷啊！~ 我想应该还有更加简洁的方法，大家不妨贴出来看看啊