0

I did review the following, it did help in some aspects, but not to find a final solution:

C# replace strings in array with LINQ

Replacing characters in a string array with linq

Linq to SQL replace .Any() with .Contains()

How to replace any in Linq

string replace using Linq in c# This one might work, but I am currently not sure if it is worth the effect converting all the code using lists in stead of arrays

Replacing values in a list inside a Linq query with values from a dictionary

Extract from the source document:

Albania Euro 97
Algeria Euro 110
Angola US $ 303 Antigua and Barbuda US $ 220
Argentina US $ 133
Armenia US $ 220
Austria Euro> 131
Australia A $ 230
Azarbaijani US $ 145

The source document (only pdf, after many requests and years still no CSV, etc.) contain multiple version of the same currency. Example: USD

  • US $
  • US (S)
  • etc.

Have setup the follow arrays to try and provide some sort of standardization:

Which works well

var incCurrDollar = new[] { "US dollar ($)", "US ($)", "US $" };
var incCurrEuro = new[] { "Euro (€)", "Euro" };
var incCurrPound = new[] { "Pounds Sterling (£)", "British Pounds" };
var incCurrAus = new[] { "Australian $", "A ($)", "Australian ($)" };
var incCurrZAR = new[] { "RSA Rand (R)", "RSA Rand", "Rand" };
var incCurrKHN = new[] { "Hong Kong ($)", "Hong Kong $", "HK $" };
var incCurrNZL = new[] { "New Zealand ($)", "New Zealand $", "NZ $" };

Employeed in the following way:

if (rCurrency == "")
{
   rCurrency = incCurrAus.Any(x => exRowCurrent.Contains(x)) ? "Australian ($)" : "";
   rCurrencyUnit = incCurrAus.Any(x => exRowCurrent.Contains(x)) ? "AUD" : "";
}

Is there a way to also replace the applicable content of exRowCurrent with the standardize version?

3
  • Isn't this a search and replace job? Commented May 26, 2023 at 8:36
  • Yes, but is there a quick and simple way to do it? Potencially something like this: foreach (var repCurreny in incCurrAus) { exRowCurrent.Replace(exRowCurrent, repCurreny); } Commented May 26, 2023 at 8:40
  • What does quick refer to, quick replacement or quick coding? I think the way is simple enough. If you mean quick coding, I think it's also quick enough, you just need several for loops. Commented May 26, 2023 at 8:43

1 Answer 1

0

This seems to be the most quick and simple way (It just seemed too simple :) )

rCurrency = incCurrAus.Any(x => exRowCurrent.Contains(x)) ? "Australian ($)" : "";
rCurrencyUnit = incCurrAus.Any(x => exRowCurrent.Contains(x)) ? "AUD" : "";
foreach (var repCurrency in incCurrAus)
{
   exRowCurrent = exRowCurrent.Replace(repCurrency, rCurrency);
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.