2013-09-29 14 views
1

我有了以下變量的應用程序:在SQLite的字符串使用變量字段

public static final String BUSINESS_NAME = "Blahr Industries"; 

但該字符串將取決於誰的應用程序定製改變: (因此,例如,另一個應用程序可能be)

public static final string BUSINESS_NAME = "Blech LTD"; 

現在我還有一個數據庫,其中包含每個應用程序版本的相同信息。當檢索到的,並隨後顯示的應用將需要放在BUSINESS_NAME變量在正確的位置: (即)

String contentText = "Yada yada, blah blah, promises promises at _____ and we will all be happy"; 

其中 「_ _」= BUSINESS_NAME

**問題**

有沒有辦法在字符串對象中放置一個變量標記(參數?),Android會在顯示並且填充時識別它? 換句話說,是否可以將「contentText」字符串插入到SQLite數據庫中,以便返回並顯示時它會在其他文本中顯示更正的商業名稱?

我已經閱讀了一些關於SQL參數的內容,但沒有正確理解它們。

感謝您的協助。

+0

您是否嘗試過與string.replace'()'字符串? –

回答

3

你可以把這個數據庫

String dbEntry = "Yada yada, blah blah, promises promises at %s and we will all be happy"; 

,當你從數據庫中檢索,格式化這樣

String contentText = String.format(dbEntry, BUSINESS_NAME);