私には文字列a5bc2cdf3
があります。私はそれをaaaaabcbccdfcdfcdf
に広げたいと思います。結果の文字列が連続して2回現れる「BC」の5つの連続「」S、「BC2」の結果が含まれている必要があり、そしてcdf
は3
回繰り返す必要がありますので、文字列で いくつかの条件に基づいてRubyの文字列を拡張するには?
は、a5
あります。
入力がa5bc2cdf3
で、出力がaaaaabcbccdfcdfcdf
の場合、どうすればRubyメソッドで行うことができますか?
def get_character("compressed_string",index)
expanded_string = calculate_expanded_string(compressed_string)
required_char = expanded_string(char_at, index_number(for eg 3))
end
def calculate_expanded_string(compressed_string)
return expanded
end
適切な文法を使用するように注意してください。 "私"は "私"です。 Stack Overflowはディスカッション・リストではなくオンラインの参考書であり、文法、スペル、句読点および書式設定の問題です。 –