Android Question remove a character from a string (Solved)

Colin Evans

Active Member
Licensed User
Longtime User
Hi, I'm not getting my head around this problem tried a few ways but with no success, basically, I have a string of numbers 12345678910 which are the players numbers 1 to 10, as a player is removed I want to remove his number from the string, next player is removed so is his number, etc. until there is only one number left, the winner

I'm sure there must be a better way of doing this, is the string method the best, or am I better to create an array, or use maps, I'm just having a mental block, any help is greatly appreciated
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
String (as comma separated), Arrays, List, Maps can all be used.

Don't think too much into it, just pick one and start coding
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Works OK until you get into double digits, but as @mcqueccu says there are multiple ways of doing it:
B4X:
    Dim Players, PlayerToRemove, NewPlayers As String

    Players = "123456789"
    PlayerToRemove = "6"
    NewPlayers = Players.Replace(PlayerToRemove,"")
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
mcqueccu thanks, I did and it was simpler than I thought

playersChk = "12345678910" so the following to remove player2, not always 10 players that's where NumPlayers comes in, thanks again just needed a shove ?

B4X:
periods = playersChk
        Log("periods " & periods)
        split1 = periods.SubString2(0,1)
        split2 = periods.SubString2(2,NumPlayers)
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Works OK until you get into double digits, but as @mcqueccu says there are multiple ways of doing it:
B4X:
    Dim Players, PlayerToRemove, NewPlayers As String

    Players = "123456789"
    PlayerToRemove = "6"
    NewPlayers = Players.Replace(PlayerToRemove,"")
I like your way of doing it better just have to 0 to 9 and it works for 10 players, thanks
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
Works OK until you get into double digits, but as @mcqueccu says there are multiple ways of doing it:
B4X:
    Dim Players, PlayerToRemove, NewPlayers As String

    Players = "123456789"
    PlayerToRemove = "6"
    NewPlayers = Players.Replace(PlayerToRemove,"")
Yes I foresee the double digits with String REPLACE will not work.
That is why i added in the braces (csv format) eg. "1,2,3,4,5,6,7,8,9,10"
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Hi, I'm not getting my head around this problem tried a few ways but with no success, basically, I have a string of numbers 12345678910 which are the players numbers 1 to 10, as a player is removed I want to remove his number from the string, next player is removed so is his number, etc. until there is only one number left, the winner

I'm sure there must be a better way of doing this, is the string method the best, or am I better to create an array, or use maps, I'm just having a mental block, any help is greatly appreciated
Going with a list or a map will save a lot of trouble/complexity.
It is simple to concatenate a list or map to a string if needed (eg to display the players).

RBS
 
Upvote 0

emexes

Expert
Licensed User
I like your way of doing it better just have to 0 to 9 and it works for 10 players

Or the Y2K solution of redefining a digit to hexadecimal and having 10 players 123456789A
(bought an extra 60 years eg 97, 98, 99, A0, A1, A2, A3 ... F9) (or 160 years if you were ok to continue to Z9)

Or using letters instead of numbers and having 10 players ABCDEFGHIJ eg Chr(64 + 1) to Chr(64 + 10)
(and potentially up to 26 players)
 
Upvote 0
Top