【问题标题】:String replace android?字符串替换android?
【发布时间】:2013-09-02 14:44:04
【问题描述】:

我正在尝试替换一个字符:在生成的系统日期上,以便我可以将其作为标题。它给了我格式:“2013 年 2 月 29 日之前 7:42:19 p.m.”,所以我需要用字符串替换来更改“:”为“”。但我不知道该怎么做。我很感激你的帮助。这是我的代码:

    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)
             {

             }
    }

【问题讨论】:

标签: java android eclipse string pdf


【解决方案1】:

是你想要的吗:

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

【讨论】:

    【解决方案2】:

    试试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.

    【讨论】:

      猜你喜欢
      • 2012-12-10
      • 2012-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-26
      • 2015-02-28
      相关资源
      最近更新 更多