String.split isn't working correctly.

Hello,

I have a list of job titles and the location of that job in a string (e.g. Retail Assistant - Batley, West Yorkshire).

I am trying to use String.Split to separate the two parts into their own variables, but it is not working, some of the strings split correctly. They all use the same character to separate them (‘-’) but it just doesn’t work.

I have this code to Debug it.

for(int i = 0; i < feed.feed.Items.Count; i++){
            string[] split = feed.feed.Items[i].Title.Split(new char[]{'-'}, 2, System.StringSplitOptions.RemoveEmptyEntries);

            foreach(string w in split){
                Debug.Log(w.Trim());
            }
}

feed.feed.Items is a System.collections.generic List of the Job - Location strings.

Here are my Debugs.

Apprentice Retail Assistant – Batley, West Yorkshire
Apprentice Sales/Telesales
Preston, Lancashire
Apprentice Sales Executive – Stockport, Cheshire
Apprentice Business Administrator – Burnley, Lancashire
Apprentice Customer Service Assistant – Burnley, Lancashire
Apprentice Sales Executive –Nelson, Lancashire
Apprentice Business Administrator – Morley, West Yorkshire
Apprentice Sales Executive – Blackburn, Lancashire
Apprentice Customer Service Executive – Blackburn, Lancashire
Apprentice Business Administrator – Blackburn, Lancashire
Apprentice Admin Executive – Shipley, West Yorkshire
Apprentice Warehouse Operative – Haslingden, Lancashire
Apprentice Front of House Assistant / Receptionist – Chorley, Lancashire
Apprentice Admin Executive – Blackburn, Lancashire
Apprentice Admin Executive – Blackburn, Lancashire
Apprentice Kitchen Assistant – Hale, Cheshire
Apprentice Front of House Assistant – Hale, Cheshire
Apprentice Front of House Assistant – Bury, Greater Manchester
Apprentice Business Administrator – Wakefield, West Yorkshire
Apprentice Care Assistant – Rawtenstall, Lancashire
Apprentice Business Administrator
Manchester City Centre
Apprentice Front of House – Dewsbury, West Yorkshire
Apprentice Care Assistant – Rossendale, Lancashire
Apprentice Care Assistant – Rossendale, Lancashire
Apprentice Care Assistant – Ramsbottom, Greater Manchester
Apprentice Customer Service Administrator
Preston, Lancashire
Apprentice Care Assistant – Sale, Cheshire
Apprentice Business Administrator – Altrincham, Cheshire
Apprentice Chef – Leeds, West Yorkshire

Could you provide a dump of the source your setting up your feed object with?

I’d rather not, it’s from a paid asset. I could get in trouble for releasing course code. It is literally just a list of strings though.

You pass a hyphen-minus (Unicode: U+002D) as a seperator but the logs (and thus probably the original strings) contain the EN Dash (Unicode: U+2013).

1 Like

It’s hard to shake the feeling sometimes that this forum is a place to help students with their programming homework…

1 Like

It’s not homework. It’s for a client’s mobile app - please take your negativity elsewhere, thanks everyone else for your help.

Sorry, I can now see the misinterpretation of the source. I didn’t mean your source code, but the source content that you feed into the feed object. Like Suddoha I suspected that you potentially could be using different characters to split within your argument.

1 Like