字符串替换android?

时间:2013-08-30 00:54:25

标签: java android eclipse string pdf

我试图替换一个字符:在生成的系统日期上,我可以把它作为标题。它给了我格式:“前29,2013 7:42:19下午”,所以我需要更改“:”为“”,用字符串替换。但我不知道该怎么做。我很感激你的帮助。继承我的代码:

    public void createPDF()
    {
        Document doc = new Document();


         try {
             Date date = new Date();
            String dateTime = DateFormat.getDateTimeInstance().format(date);
             File sdCard = Environment.getExternalStorageDirectory();
             File dir = new File (sdCard.getAbsolutePath() + "/Bitacora");
             dir.mkdirs();
             File file = new File(dir, "Bitácora "+idetotrocliente.getText().toString()+", "+dateTime+etsitio.getText().toString()+".pdf");
             FileOutputStream fOut = new FileOutputStream(file);
                 }
             catch(Exception)
             {

             }
    }

2 个答案:

答案 0 :(得分:6)

尝试String.replace(old, new)

String dateTime = "ago 29, 2013 7:42:19 p.m.";
dateTime = dateTime.replace(":", " ");
System.out.println("dateTime : "+dateTime);

输出:dateTime : ago 29, 2013 7 42 19 p.m.

答案 1 :(得分:2)

这是你想要的:

 String orig = "ago 29, 2013 7:42:19 p.m.";
String updated = orig.replace(":", " ");
System.out.println(updated);