Function to Read short text file into Swift

Peruttu Julkaistu 6 vuotta sitten Maksettu toimituksen yhteydessä
Peruttu Maksettu toimituksen yhteydessä

I need a Swift 4 function in OSX to read in text files with the following format:

8

Fill Level

0% 8 0 0.1 0.2 0.3 0.5 0.7 0.8 1

0.05 0.04 0.04 0.035 0.03 0.03 0.02 0

10% 9 0 0.1 0.15 0.2 0.3 0.5 0.7 0.9 1

0.4 0.4 0.4 0.25 0.26 0.26 0.25 0.25 0

...

Here is the ~~ c# code that read it in. You don't need to follow this code but it shows the structure. Hopefully there is an easier way to read this in with Swift.

var NFL: Int

var NP: [Int]

var FLEV: [Double]

var GNU: [[Double]]

var LAM: [[Double]]

init()

{

var type = 4

}

/// <summary>

/// Read Fluid Curves

/// </summary>

func ReadFluidCurves() -> Bool

{

var fileName = "[login to view URL]"

StreamReader input = new StreamReader(fileName);

NFL = [login to view URL]( ReadJunk( input));

FLEV = new double[NFL];

NP = new int[NFL];

GNU = new double[NFL][];

LAM = new double[NFL][];

for (int i=0;i<NFL;i++) {

FLEV[i] = [login to view URL]( ReadJunk( input));

NP[i] = [login to view URL]( ReadJunk( input));

GNU[i] = new double[NP[i]];

for (int j=0;j<NP[i];j++)

{

GNU[i][j] = [login to view URL]( ReadJunk( input));

}

LAM[i] = new double[NP[i]];

for (int j=0;j<NP[i];j++)

{

LAM[i][j] = [login to view URL]( ReadJunk( input));

}

}

return true

}

func ReadJunk(StreamReader input) -> String

{

char[] buffer = new char[10];

String buildup = "";

[login to view URL](buffer, 0, 1);

while (buffer[0] == ' ' || buffer[0] == (char)13 || buffer[0] == (char)10 )

{

[login to view URL](buffer, 0, 1);

}

buildup = new String( buffer[0], 1);

[login to view URL](buffer, 0, 1);

while (buffer[0] != ' ' && buffer[0] != (char)13 && buffer[0] != (char)10)

{

buildup = buildup + new String( buffer[0], 1);;

[login to view URL](buffer, 0, 1);

}

return buildup;

}

Objective C Swift

Projektin tunnus: #15355752

Tietoa projektista

2 ehdotusta Etäprojekti Aktiivinen 6 vuotta sitten

2 freelanceria on tarjonnut keskimäärin $70 tähän työhön

Beauty1409

Hello, I've reviewed your job description very carefully and got the idea on what you are looking for. I can complete this project and also can start it quickly. Thanks Relevant Skills and Experience Objective C, Swi Lisää

$100 USD 1 päivässä
(13 arvostelua)
4.5