#String split

60 messages · Page 1 of 1 (latest)

sick flume
#

Hey I am trying to make something that reads a string and splits it into different elements on a list so like [xxx yyy] would make ((index[0] = xxx),(index[1] = yyy)) I want the delimeter to be new line or space. How would I go about this?

honest vaultBOT
#

Hey, @sick flume!
Please remember to /close this post once your question has been answered!

sick flume
#

halp

tribal jetty
#

Have you tried split() ?

sick flume
#

nor know how to use

#

properly

tribal jetty
#

Read up on it then

sick flume
#

so

#

did

#
        System.out.println("Please enter Keys");
        String keys = input.next();

        System.out.println("Please enter Loader Link");
        String loader = input.next();

        List<String> list = new ArrayList<String>(Arrays.asList(keys.split("\n")));
#

have this

#

but

#

it splits after one use

#

I want it to add each item

#

right now I paste

#
V9W62Q36u0kgLpLdBvZ57cImNmX09z
BbBgtVaS800yH8KyTs4q1l9jCoGeM7
XxYbq7b4qIb5Ev45ZyTdZyTjJ562Q7
4bWlf5jX4BbdVr0cHh5o8mSyJ6CmKt
SuS7364N72iz0w5pJfE7774oS6DqZg
QhMpwW6CpOor0g48LsYd89ZsP0A2Vi
WeZ4bWbI8Nym7e7p5zM77s0jBqPuW3
F90znJ5DqO3vLpRjLi32AtGy67OaL8
BvYb341ZuKci6lLl44WsPsN9EfLxF1
8fZlnEsZ6FugTfEw9n80F1GzFdIqRy
9gYdhCoR087z6e0rKwZcBdZbFxJ87k
Gm9prVrUhOj6OwL7Eu4pStO050Rh9x
Aq3g13bAqPpePy2aV4GsCyV02mJiQq
501uhA0WjVg49qZmC17zI5VeObRcRt
EuYhl576xYl5F3P049M6JdQ2L1LmSm
#

as a test

#

and it skips "loader"

#

and idk why

#

it takes second row as string for it

tribal jetty
#

The call of next() supposes that you're using a Scanner. A Scanner already splits

sick flume
#

it splits wrong for what I want

#

I want to paste a list like above

#

and then grab it all as a string and break it into a list

#

thats where I am lost

tribal jetty
#

But you're asking for keys then for a loader

#

Obviously the loader will be following the keys

#

It should be obvious that your idea doesn't work

sick flume
#

I have no other idea

#

on how

#

is my issue

#

just learning gfx so trying to make a crude method

tribal jetty
#

On how what? Computers are not magical. If you want to ask for keys first and for a loader then, you need to design a thing that tells them apart

sick flume
#

ye thats what I am confused on

#

tryin to

#

first idea and simplest was get "string" then split

#

dumb the computer does that

tribal jetty
#

If it's in some file you could read up on how to read JSON files

#

That way you'd put your keys in an array and the rest elsewhere

sick flume
#

I havent really learned how to read json so I might have to read up on it

sharp trail
#

Then split()

sick flume
#

But it only reads one line to key then next line to loader

sharp trail
sick flume
tribal jetty
#

I have a feeling they didn't read the issue

sharp trail
# sick flume Hey I am trying to make something that reads a string and splits it into differe...

./run ```java
String line = """
V9W62Q36u0kgLpLdBvZ57cImNmX09z
BbBgtVaS800yH8KyTs4q1l9jCoGeM7
XxYbq7b4qIb5Ev45ZyTdZyTjJ562Q7
4bWlf5jX4BbdVr0cHh5o8mSyJ6CmKt
SuS7364N72iz0w5pJfE7774oS6DqZg
QhMpwW6CpOor0g48LsYd89ZsP0A2Vi
WeZ4bWbI8Nym7e7p5zM77s0jBqPuW3
F90znJ5DqO3vLpRjLi32AtGy67OaL8
BvYb341ZuKci6lLl44WsPsN9EfLxF1
8fZlnEsZ6FugTfEw9n80F1GzFdIqRy
9gYdhCoR087z6e0rKwZcBdZbFxJ87k
Gm9prVrUhOj6OwL7Eu4pStO050Rh9x
Aq3g13bAqPpePy2aV4GsCyV02mJiQq
501uhA0WjVg49qZmC17zI5VeObRcRt
EuYhl576xYl5F3P049M6JdQ2L1LmSm
""";
String[] parts = line.split("\n");
System.out.println(parts.length);
System.out.println(parts[3]);

safe whaleBOT
#

Here is your java(15.0.2) output @sharp trail

15
4bWlf5jX4BbdVr0cHh5o8mSyJ6CmKt
sharp trail
safe whaleBOT
#

Here is your java(15.0.2) output @sharp trail

2
xxx
yyy
sick flume
#

ah so you are saying to manually set the "string"

#

as the keys

sharp trail
sick flume
#

Ill give it a shot

inland prairie
#

@sick flume if you are done with the channel pls close it