小编new*_*ser的帖子

用于匹配 S3 文件和目录的正则表达式

我有以下用于匹配S3URL 的模式

Pattern.compile("^s3://([^/]+)/(.*?([^/]+))$");
Run Code Online (Sandbox Code Playgroud)

这匹配

s3://bucket/path/key
Run Code Online (Sandbox Code Playgroud)

但不匹配目录

s3://bucket/path/directory/
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法可以更改pattern来匹配目录?

java regex

3
推荐指数
1
解决办法
2万
查看次数

如何将"\ ,, /"显示为字符串

我想\ ,,/在Java中显示 为字符串,但我得到无效的转义序列.

尝试了所有可能的方法

   String Metal= "'\'"+",,/";

   Toast a= Toast.makeText(getApplicationContext(), Metal, Toast.LENGTH_LONG);
   a.show();

   String Metal= "\"+",,/";
Run Code Online (Sandbox Code Playgroud)

得出结论 ",,/

我怎样才能做到这一点?

java string android

3
推荐指数
1
解决办法
129
查看次数

用动态值替换字符串中的动态标签数量 - Java

我已经通过这个网站和谷歌搜索过,但我找不到针对我所面临的这个问题的具体解决方案。

语言:Java

我有一个字符串,让我们说:

String message = "I would like to have <variable>KG of rice and <variable>Litre of Milk. I only have $<variable>, is this sufficient?"
Run Code Online (Sandbox Code Playgroud)

现在,用户将拥有三个文本字段,它们将被排序以填充变量。

约束:

1) 用户可以在消息中输入尽可能多的标签

2) 将出现的文本字段的数量基于消息中的标签数量

无论如何我可以将原始消息替换为:

“我想要 {0} 公斤大米和 {1} 升牛奶。我只有 {2} 美元,够了吗?”

我正在更改为 {X},其中 X=订单号。如何实现这一目标?

我想过使用格式化程序、匹配器,但我一直都在死胡同。那么,有人可以帮助我吗?

谢谢你

java string

3
推荐指数
2
解决办法
4990
查看次数

练习吧!1.2.3:奇怪

我是学习Java的新手,我也在练习它!问题有助于我理解语言.

我陷入问题1.2.3,标题为Strange,在这个问题中,他们希望您根据他们提供的代码输出输出.

我的问题是,与输入相比,我不理解输出.

 public class Strange {

 public static void main(String[] args) {
    first();
    third();
    second();
    third();
 }

 public static void first() {
    System.out.println("Inside first method.");
}

public static void second() {
    System.out.println("Inside second method.");
    first();
 }

 public static void third() {
    System.out.println("Inside third method.");
    first();
    second();
 }
}
Run Code Online (Sandbox Code Playgroud)

我认为输出将是:

Inside first method.
Inside third method.
Inside first method.
Inside second method.
Inside second method.
Inside first method.
Inside third method.
Inside first method.
Inside second method.
Run Code Online (Sandbox Code Playgroud)

但它是:

Inside first …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
2
解决办法
1973
查看次数

像Microsoft一样使文本居中

我想将文本对齐方式编辑到中心.我已经知道你可以这样做:intro.setHorizo​​ntalAlignment(JLabel.CENTER); 使它居中.但我想这样做,以便当你做那个图标时,就像在微软的话.到目前为止这是我的程序:

import javax.swing.*;

import javax.swing.JLabel;

public class FrameStuff

{

 public static void main(String[] args)

 {

 // Creating and setting up a regular frame
 JFrame frame = new JFrame();

 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 // Setting up frame characteristics
 frame.setSize(800, 600);
 frame.setTitle("FrameStuff");

 // Making it visible

frame.setVisible(true);

 //Making and assigning a new string

String textintro = new String("<html>This is my program <br/>I am having loads of fun <br/>Thanks for helping me!</html>");

// Made a new label (just happened to call it intro

 JLabel intro …
Run Code Online (Sandbox Code Playgroud)

java swing jlabel jframe centering

1
推荐指数
1
解决办法
68
查看次数

标签 统计

java ×5

string ×2

android ×1

centering ×1

jframe ×1

jlabel ×1

regex ×1

swing ×1