I have a svg file in string format which look like this http://jsfiddle.net/mumg81qq/5/ This file contains color code in either hex/rgb format.
i want to extract these two different types of colors format in two arrays.
hex colors could be in format of
fill:#303744
---OR---
fill="#020202"
and rgb colors could be in format of
fill:rgb(48,49,55)
---OR---
fill="rgb(205,149,36)"
resultant array should look like this
hexColor = ["#303744","#020202"]
rgbColor = ["rgb(48,49,55)","rgb(205,149,36)"]
I could only managed to write code which search one type of hex string .
string searchHex1 = "fill=\"#", searchHex2 = "fill:#";
string searchRGB1 = "fill=\"rgb(", searchRGB2 = "fill:rgb(";
List<string> hexColor = new List<string>();
List<string> rgbColor = new List<string>();
string sHexColor = "";
int index = 0;
do
{
index = svgFile.IndexOf(searchHex1, index);
if (index != -1)
{
sHexColor = svgFile.Substring(index, 7);
if (!hexColor.Contains(sHexColor))
{
hexColor.Add(sHexColor);
}
index++;
}
} while (index != -1);
in most efficient way i want to search 4 different types of hex & rgb colors and store it in two different arrays.
