大家好,我是飞刀,这次我来讲一下格式化字符串的功能。

首先打开界面看一下:

android 格式化打印 安卓格式化代码_java

输入框就一个,这里举例输入“关注”,点击生成,结果如下:

android 格式化打印 安卓格式化代码_字符串_02

FocusOn
focusOn
focus_on
FOCUS_ON
public static final String FOCUS_ON="focus_on";//关注
public static final String FOCUS_ON="";//
FocusOnBean
android:id="@+id/tv_focus_on"

输入的字符串自动翻译并转换成常用的各种字符串。有首字母大写,驼峰式,下划线,下划线全大写,常量,bean,控件id。

也可以直接输入英文,如hello world,得到结果:

HelloWorld
helloWorld
hello_world
HELLO_WORLD
public static final String HELLO_WORLD="hello_world";//
public static final String HELLO_WORLD="";//
HelloWorldBean
android:id="@+id/tv_hello_world"

输入hello,得到结果:

Hello
hello
hello
HELLO
public static final String HELLO="hello";//
public static final String HELLO="";//
HelloBean
android:id="@+id/tv_hello"

输入HelloWorld,得到结果:

HelloWorld
helloWorld
helloworld
HELLOWORLD
public static final String HELLOWORLD="helloworld";//
public static final String HELLO_WORLD="";//
HelloWorldBean
android:id="@+id/tv_helloworld"

输入Hello World,得到结果:

HelloWorld
helloWorld
hello_world
HELLO_WORLD
public static final String HELLO_WORLD="hello_world";//
public static final String HELLO_WORLD="";//
HelloWorldBean
android:id="@+id/tv_hello_world"

输入“点赞 投币 收藏”,得到结果:

ThumbUpCoinCollection
thumbUpCoinCollection
thumb_up_coin_collection
THUMB_UP_COIN_COLLECTION
public static final String THUMB_UP_COIN_COLLECTION="thumb_up_coin_collection";//点赞 投币 收藏
public static final String THUMB_UP_COIN_COLLECTION="";//
ThumbUpCoinCollectionBean
android:id="@+id/tv_thumb_up_coin_collection"

那么输入“一键三连”,会得到什么结果呢?请看:

ThreeEvenAKey
threeEvenAKey
three_even_a_key
THREE_EVEN_A_KEY
public static final String THREE_EVEN_A_KEY="three_even_a_key";//一键三连
public static final String THREE_EVEN_A_KEY="";//
ThreeEvenAKeyBean
android:id="@+id/tv_three_even_a_key"

 

以上就是这个模块的主要功能了,翻译结果是有道api返回的,至于准不准确的问题,我们不用考虑,因为这个字符串只是用来大概标记识别的,只要看上去能大概知道是什么意思就行了,不要求非常准确的翻译。变量名,类名等可以直接用,如果要求高的话也可以自己适当调整,但是千万不要用拼音命名,这是编程大忌。

 

最近还添加了一个非常棒的功能,就是支持swagger的接口转换,如下图:

android 格式化打印 安卓格式化代码_字符串_03

复制某行接口,如:

android 格式化打印 安卓格式化代码_android 格式化打印_04

注意要整行选中,swagger的文档有点特殊,复制的时候要小心,从get的前面或后面开始往右拖动选中复制,放入输入框中会自动换行,不用去调整。点击生成,得到结果:

android 格式化打印 安卓格式化代码_输入框_05

HomeContent
homeContent
home_content
HOME_CONTENT
public static final String HOME_CONTENT="home_content";//
public static final String HOME_CONTENT="/home/content";//首页内容页信息展示
HomeContentBean
android:id="@+id/tv_home_content"

 

这里我们一般只用到下面两个字符串:

public static final String HOME_CONTENT="/home/content";//首页内容页信息展示
HomeContentBean

第一个是接口url地址的定义,可以复制到自己的HttpConstant常量类中。

第二个是接口返回的Json映射成JavaBean的名称,可以填入Json转Bean那个模块的类名中使用:

android 格式化打印 安卓格式化代码_字符串_06

 

好了,今天的内容分享就到这了,我们下篇见。