1

So I have a array, where key:value are recorded as single unit. I want to split the array and record key and value as an individual.

Example

array = ["Image loaded:", "RuleName: xx", "UtcTime: xxx", "ProcessGuid: {xxx}", "ProcessId: 884", "Image: C:\\opt\\td-agent\\bin\\ruby.exe", "ImageLoaded: xxx", "FileVersion: -", "Description: -", "Product: -", "Company: -", "OriginalFileName: -", "Hashes: MD5=xxx", "Signed: false", "Signature: -", "SignatureStatus: Unavailable", "User: xx"]

Now given I want to loop it and extract key:value

LOOP THROUGH ARRAY
array[i] = array.split(',',key,value)
print(key)
print(value)

1
  • Array.instance_methods.include?(:split) #=> false. When you give an example please show the desired result (here a hash). Lastly, there is no need for array to have so many elements. Commented Oct 13, 2022 at 0:45

1 Answer 1

2

If you want do build a new array with keys and values splited, you can do that:

new_array = array.map {|a| a.split(":")}
new_array[0][0] # First key value
new_array[0][1] # First value
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.