Question

Is it possible to use Guids as the identifier in resource files?

In my program the user will be able to chose between some possible types when he creates an item. Which item was chosen is saved via a Guid.

But the hyphens in the Guids seem to be a problem for the resource files. Is there a better solution that to use Replace in order to remove every hyphen from the Guid before looking up the typename in the current language?

Was it helpful?

Solution

How are you turning the Guids into strings?

You can use Guid.ToString("N") to produce a string guid without any hyphens.

You may have to put a non-digit at the start too - if you do, it's probably easiest to do it with String.Format():

string guidStr = string.Format("X{0:N}", Guid.NewGuid()); // Prefix with "X"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top