#Separating|Decoding 1 Line

62 messages · Page 1 of 1 (latest)

karmic edge
#

Hello I am trying to decode multiple lines of code and I am stuck on how to separate/assign values to each alphabet. (See example below)

#

a:123;b:456;c:789;id:c11ba3#2b#a

#

a is a letter that represents the number sequence 123

#

after id I need to look at every alphabet and replace each alphabet with whichever number sequence it is represented by

exotic shoal
#

this question was just asked like, a couple hours ago maybe?

#

was that you? did you delete the original? I don't see it

karmic edge
#

haha yea it was somebody else in my study group, however we are still stuck at this step after trying to figure it out for hours

exotic shoal
#

there are quite a few ways to approach this kind of thing

#

this sounds academic and somewhat arbitrary

#

so a naive approach is probably fine

#

meaning, you could go all the way into parser and compiler theory for this kind of stuff, but you probably don't need to

#

a simple approach would be basically just do a bunch of string splits

#

first split on ; and then split each of those on :

#

finally do a basic std::regex replace on the last value

marble trout
#

Noobie here, but he could also use a map

exotic shoal
#

sure?

marble trout
#

map with a-z keys and int value

exotic shoal
#

nothing I said implies what storage destination type to use exactly

marble trout
#

Not implying that either just saying you're the more experienced one

paper birch
#

this assignment is on string manipulation, so we were trying to go about it with vectors

#

but we arent experienced with them so we arent sure what functions we can use or how the syntax would work

exotic shoal
#

a map would probably be the natural container choice for the initial key value pairs

karmic edge
#

we are not too familiar with what a map is, is it something I could easily look up and learn? or is it more complex

exotic shoal
#

I mean, I don't know what functions you can use either

marble trout
exotic shoal
#

meaning, idk if your course or professor has restrictions

#

without restrictions, everything you need is in stdlib

paper birch
#

it doesnt

marble trout
#

imho

paper birch
#

were welcome to utilize whatever we find on the internet so long as credit is given

exotic shoal
#

std::getline and various functions in <regex> and <string> all will get you where you need to go

paper birch
#

i thought getline was for when u had parameters to go by?

marble trout
#

Should they be using regex tho?

#

It's really slow

exotic shoal
#

I don't think that matters here

karmic edge
#

^

exotic shoal
#

it's an academic/school project

karmic edge
#

speed does not matter atm

paper birch
#

yes, homework assignment

marble trout
#

Well fair enough

marble trout
#

Might be useful

#

ngl tho this is a nice course

#

We had to reinvent the wheel on ours 💀

#

Multiple times

paper birch
#

were not sure how to implement the vector functions in our for loop

#

so our idea is wanting to use substr to categorize the information between : and ;

#

we have this

#

but were not sure whether that would work because id is also an alpha, so were trying to go about it with the colons

marble trout
#

What is the isalpha

paper birch
#

its checking for an alphabetic character

#

we've written a bit more to narrow it down

#

vector <char> letter; would be the 'a' and the vector <string> decoder would be the '123' or numbers associated with it

marble trout
#

I need to sleep, hope someone else can help

paper birch
#

i appreciate your help and ideas with the different function ideas

marble trout
#

You're welcome! Best of luck

tranquil basinBOT
#

@karmic edge

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

#

@karmic edge

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.