【问题标题】:How to convert a single address line into three address lines like Adress line 1,address line 2 ,address line 3 in java如何在java中将单个地址行转换为三个地址行,例如地址行1,地址行2,地址行3
【发布时间】:2021-05-14 06:33:26
【问题描述】:

我需要在java中将单个地址行转换为三个地址行

Address line - Wadgaon Shelke nagar ,Ganesh Garden Society ,A Building B B wing Flat no-3

Address line 1- Wadgaon Shelke nagar 
Address line 2- Ganesh Garden Society 
Address line 3 -A building B wing Flat no 3

【问题讨论】:

  • 根据什么规则/逻辑?也许在,!? 处分开?
  • 您需要指定如何识别地址行 1、2 和 3。它们之间的区别是什么?
  • 如果我们将第一个地址行存储在 3 个空格之后
  • 只需使用string.split(" ,")。这将为您提供一个字符串数组,您可以将其打印在不同的行中。

标签: java arrays string


【解决方案1】:

这个问题的简单答案。

使用split()方法来实现你的输出。

我已经稍微改变了地址行的结构。

Address line - Wadgaon ,Shelke nagar |Ganesh Garden Society |A Building B B wing Flat no-3

我没有用, 分隔不同的地址,而是使用另一个符号|。你可以使用任何你想要的。

现在在这个字符串上调用split() 方法。我们称这个字符串为adddressLine

String addressLine = Wadgaon ,Shelke nagar |Ganesh Garden Society |A Building B B wing Flat no-3;

String[] ans = addressLine.split("\\|");
For(String str : ans){
    System.out.println(str);
}

在这里,我基本上在找到| 符号的位置拆分 addressLine 字符串。

查看我在下面提到的答案,了解为什么 addressLine.split("|") 不起作用。

我希望这会有所帮助。

Check this answer for more info

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-09
    • 2011-02-16
    • 1970-01-01
    • 2013-05-13
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    相关资源
    最近更新 更多