United Kingdom's three-name-cities; is there a generic way to write them?

There isn't a standard. You just have to memorize them. :) On the one hand, you have:

  • Stratford-upon-Avon
  • Stoke-on-Trent

On the other, you have:

  • Kingston upon Hull
  • Newcastle upon Tyne

In the cases of lesser-known towns, the dashed approach seems to be used far more commonly when the town's name features a preposition, such as the examples below. This practice generally does not carry over town names of three words or more that do not contain prepositions, such as Welwyn Garden City and Portishead and North Weston.

  • Appleby-in-Westmorland
  • Barrow-in-Ferness
  • Henley-in-Arden
  • Kirton-in-Lindsey
  • Burnham-on-Crouch
  • Chapel-en-le-Frith
  • Stockton-on-Tees

There are, however, occasional exceptions, such as:

  • Medlar with Wesham
  • Northleach with Eastington
  • Burton upon Trent

You'll even find one or two towns that seem to disobey all statutes of sense, like Burnham-on-Sea and Highbridge (that's a single town). I can't speak to why the dash is used, except in that it might help people read multi-word town names cohesively (but really, Stratford-upon-Avon literally is Stratford upon Avon). It does seem the majority of towns use the dash, but there are several examples of towns and cities that omit it. As such, my advice is to check external references before assuming.