using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("test 1 = " + getFileName("region 1", "UNArpC1C6A03"));
}
static String getFileName(String n1, String n2)
{
try
{
String v = "";
int16 SubstringPosition = 0;
int16 StrLen = n2.len;
switch (n1.ToLower())
{
case "region 1":
default:
v = n2.Substring(0, SubstringPosition - 1) + "C1C2" + n2.Substring(SubstringPosition + 5, StrLen);
break;
case "region 2":
v = n2.Substring(0, SubstringPosition - 1) + "C3C4" + n2.Substring(SubstringPosition + 5, StrLen);
break;
case "region 3":
v = n2.Substring(0, SubstringPosition - 1) + "C5C6" + n2.Substring(SubstringPosition + 5, StrLen);
break;
}
return v;
}
catch (Exception e)
{
return "";
}
}
}
}
using System;
using System.IO;
using System.Windows.Forms;
using System.Collections.Generic;
using SoundForge;
// Adds regions every 16 seconds to an open audio file.
// Exports every odd region to a user supplied output directory in the same format as the original open audio file.
public class EntryPoint
{
public void Begin(IScriptableApp app)
{
// select the output directory for the exported regions
string outDirectory = SfHelpers.ChooseDirectory("Choose the output directory.", @"C:\");
ISfFileHost work_file = app.CurrentFile;
// File extension for naming the ouput files
string outExt = work_file.SaveFormat.Extension;
// undo wrapper for this script.
int scriptUndo = work_file.BeginUndo("ScriptUndo");
SfAudioSelection asel = new SfAudioSelection(work_file);
SfAudioMarkerList mark_list = work_file.Markers;
// clear any existing regions
mark_list.Clear();
long file_length = asel.Length;
double lengthLeft = work_file.Formatter.PositionToTime(file_length);
long regionLength = work_file.Formatter.TimeToPosition(16);
long currentPos = work_file.Formatter.TimeToPosition(0);
bool keepGoing = true;
int regionCount = 1;
while(keepGoing){
// check to see if there is enough length left to add the next region
if (lengthLeft > 8.0)
{
string regionName = String.Format("Region_{0}", regionCount);
// add region
mark_list.AddRegion(currentPos, regionLength, regionName);
// export to file if this is an export region
if (regionCount % 2 != 0)
{
SfAudioSelection regionSel = new SfAudioSelection(currentPos, regionLength);
string saveName = Path.Combine(outDirectory, String.Format("{0}.{1}", regionName, outExt));
exportRegionToFile(saveName, work_file, regionSel, app);
}
// update our tracking vars.
currentPos += regionLength;
lengthLeft -= 8.0;
regionCount++;
}
// else make a region out of whatever time is leftover and set keepGoing to False
else{
string regionName = String.Format("Region_{0}", regionCount);
regionLength = work_file.Formatter.TimeToPosition(lengthLeft);
mark_list.AddRegion(currentPos, regionLength, regionName);
// export to file if this is an export region
if (regionCount % 2 != 0)
{
SfAudioSelection regionSel = new SfAudioSelection(currentPos, regionLength);
string saveName = Path.Combine(outDirectory, String.Format("{0}.{1}", regionName, outExt));
exportRegionToFile(saveName, work_file, regionSel, app);
}
// stop our loop
keepGoing = false;
}
}
// close the undo wrapper
work_file.EndUndo(scriptUndo, false);
}
public void exportRegionToFile(string regionName, ISfFileHost workFile, SfAudioSelection regionSelection, IScriptableApp app){
ISfFileHost newFile = app.NewFile(workFile.DataFormat, true);
newFile.OverwriteAudio(0, 0, workFile, regionSelection);
newFile.SaveAs(regionName, workFile.SaveFormat.Guid, "Default Template", RenderOptions.WaitForDoneOrCancel);
newFile.Close(CloseOptions.SaveChanges);
}
public void FromSoundForge(IScriptableApp app)
{
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
Begin(app);
app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name));
}
public static IScriptableApp ForgeApp = null;
public static void DPF(string sz) { ForgeApp.OutputText(sz); }
public static void DPF(string fmt, params object[] args) { ForgeApp.OutputText(String.Format(fmt, args)); }
} //EntryPoint
in the filename the c1c6 is constant but text to left and right of that will change
in vba
I would use an instr to find the start position of c1c6 which would then allow me to work out what the characters were upto c1 ie c1c6 -1 and also after c6 as those will change in length whereas here I believe they are fixed
does c# substring allow me to do that?