考虑下面的字符串
String names = "Bharath-Vinayak-Harish-Punith"
Run Code Online (Sandbox Code Playgroud)
我希望以字符串的形式获得输出,它只包含Bharath.(字符串直到第一次出现" - "运算符).任何人都可以告诉我,我们怎么能这样做?
我在一些位置有4个不同的文件,如:D:\ 1.txt D:\ 2.txt D:\ 3.txt和D:\ 4.txt
我需要创建一个新文件NewFile.txt,它应该包含上述文件中存在的所有内容1.txt,2.txt,3.txt 4.txt .......
所有数据都应出现在New Single文件(NewFile.txt)中.
请建议我在java或Groovy中做同样的想法....
String val = "98"
Run Code Online (Sandbox Code Playgroud)
我需要输出为0000098
(7位数).
我需要左边填充零或字符串或整数值...
存储在val中的数字是动态的,可以包含任意数量的数字,但输出应始终为7位数.
朋友我必须在项目中捏造一些东西,我发现了一些困难,如下:
String name1 = "Bharath" // its length should be 12
String name2 = "Raju" // its length should be 8
String name3 = "Rohan" // its length should be 9
String name4 = "Sujeeth" // its length should be 12
String name5 = "Rahul" // its length should be 11 " Means all Strings with Variable length"
Run Code Online (Sandbox Code Playgroud)
我有字符串和它们的长度.我需要输出如下格式.通过使用字符串连接和填充.我需要在Groovy中回答,即使Java也很好..
"Bharath Raju Rohan Sujeeth Rahul "
Run Code Online (Sandbox Code Playgroud)
手段:
Bharath以5个黑色空格作为lenth是12(7 + 5 = 12),
Raju从4个黑色空间开始,因为lenth是8(4 + 4 = 8),
Rohan向前开了4个黑色空格,因为lenth是9(5 + 4),
Sujeeth向前5个黑色空间,因为lenth是12(7 …