How to reverse a string

前端 未结 6 1254
北荒
北荒 2021-01-15 19:53

I need to reverse the string of a user\'s input.

I need it done in the simplest of ways. I was trying to do reverseOrder(UserInput) but it wasn\'t working.

6条回答
  •  被撕碎了的回忆
    2021-01-15 20:21

    I prefer using Apache's commons-lang for this kind of thing. There are all kinds of goodies, including:

    StringUtils.reverse("Hello World!");
    

    yields: !dlroW olleH

    StringUtils.reverseDelimited("Hello World!", ' ');
    

    yields: World! Hello

提交回复
热议问题