battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum

descriptionJava string spilt and rebuild EmptyJava string spilt and rebuild

more_horiz

Code:

import java.util.ArrayList;

public class AXStringSplit {
    // may be used to prepare data before saving or after loading
    // the advantage is less data fields. for example: {skills: s1_s2_s3}
    private String spChar = "_";

    public void setSpChar(String spChar) {
        this.spChar = spChar;
    }
    public String[] split(String s1){
        return s1.split(spChar);
    }
    public String stringBuilder(String[] sArr){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < sArr.length - 1; i++) {
            sb.append(sArr[i]);
            sb.append(this.spChar);
        }
        sb.append(sArr[sArr.length - 1]);
        return sb.toString();
    }
}

descriptionJava string spilt and rebuild Emptyswift string separator to array list

more_horiz

Code:

class AXStringSplit{
    // may be used to prepare data before saving or after loading
    // the advantage is less data fields. for example: {skills: s1_s2_s3}
    private var separator:Character = "_"
    func setSeparator(separator:Character) {
        self.separator = separator
    }
    func splitStr(s1:String)->Array<String>{
        var result:Array<String> = [String]()
        let temp = s1.split(separator: self.separator)
        for item in temp{
            result.append(String(item))
        }
        return result
    }
    func stringBuilder(strArrList:Array<String>) -> String {
        return strArrList.joined(separator: String(separator))
    }
}

privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply