---
title: "MessageFormat的pattern中含有单引号的问题"
author: "winse"
date: "2013-03-18T09:42:25Z"
tags: []
categories: ["编程语言"]
slug: "messageformat-pattern"
draft: false
lastmod: "2013-03-18T09:42:25Z"
id: 1830987
url: "https://winse.iteye.com/blog/1830987"
---

类似于linux字符操作，如果被单引号包裹的字符不会被替换。

 

如果需要输出单引号，又要替换其中的字符，需要使用**双单引号**来表示单引号！

 

```
public class MessageFormatTest {
	
	@Test
	public void testPatternUncorrect(){
		String UPDATE_SQL = "update t_handle_time a set a.start_time=sysdate where table_name = 'dynamic_{0}'";

		Assert.assertEquals("update t_handle_time a set a.start_time=sysdate where table_name = dynamic_{0}",
				MessageFormat.format(UPDATE_SQL, "test"));
	}
	
	@Test
	public void testPatternCorrect(){
		String UPDATE_SQL = "update t_handle_time a set a.start_time=sysdate where table_name = ''dynamic_{0}''";

		Assert.assertEquals("update t_handle_time a set a.start_time=sysdate where table_name = 'dynamic_test'", 
				MessageFormat.format(UPDATE_SQL, "test"));
	}

}
```