Skip to content
Browse files

Implemented String#ReplaceFirst extension method

  • Loading branch information...
1 parent 8ce1c33 commit faa971547083738dc9f34c6fed644d58dc15fbed @kmees kmees committed Mar 7, 2013
View
9 src/IronSharePoint.Framework/IronSharePoint.Framework.csproj
@@ -103,16 +103,15 @@
<Compile Include="Hives\PhysicalHive.cs" />
<Compile Include="Hives\SPDocumentHive.cs" />
<Compile Include="IHive.cs" />
+ <Compile Include="IIronControl.cs" />
+ <Compile Include="IIronDataStore.cs" />
+ <Compile Include="IronCompositeControl.cs" />
<Compile Include="IronConsole\Hooks\IIronConsoleHook.cs" />
<Compile Include="IronConsole\Hooks\IronConsoleHookBase.cs" />
<Compile Include="IronConsole\Hooks\RubyConsoleHook.cs" />
<Compile Include="IronConsole\IronConsole.cs" />
<Compile Include="IronConsole\IronConsoleResult.cs" />
<Compile Include="IronConsole\IronConsoleTask.cs" />
- <Compile Include="IronConsole\IronConsoleWebPart.cs" />
- <Compile Include="IIronControl.cs" />
- <Compile Include="IIronDataStore.cs" />
- <Compile Include="IronCompositeControl.cs" />
<Compile Include="IronConstant.cs" />
<Compile Include="IronContentTypeId.cs" />
<Compile Include="IronControl.cs" />
@@ -142,11 +141,13 @@
<Compile Include="Util\BlockingQueue.cs" />
<Compile Include="Util\EnumerableExtensions.cs" />
<Compile Include="Util\IBlockingQueue.cs" />
+ <Compile Include="Util\StringExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="key.snk" />
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
15 src/IronSharePoint.Framework/Util/StringExtensions.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace IronSharePoint.Framework.Util
+{
+ public static class StringExtensions
+ {
+ public static string ReplaceFirst(this string source, string pattern, string substitute)
+ {
+ var index = source.IndexOf(pattern, StringComparison.InvariantCulture);
+ if (index < 0) return source;
+
+ return source.Substring(0, index) + substitute + source.Substring(index + pattern.Length);
+ }
+ }
+}
View
2 test/IronSharePoint.Framework.Test/IronSharePoint.Framework.Test.csproj
@@ -56,11 +56,13 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="Administration\IronHiveRegistry_Fixture.cs" />
<Compile Include="Dummy.cs" />
<Compile Include="Hive\OrderedHiveList_Fixture.cs" />
<Compile Include="Hive\PhysicalHive_Fixture.cs" />
<Compile Include="Hive\SPDocumentHive_Fixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Util\StringExtensions_Fixture.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
View
21 test/IronSharePoint.Framework.Test/Util/StringExtensions_Fixture.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using NUnit.Framework;
+using IronSharePoint.Framework.Util;
+using FluentAssertions;
+
+namespace IronSharePoint.Framework.Test.Util
+{
+ [TestFixture]
+ class StringExtensions_Fixture
+ {
+ [Test]
+ public void ReplaceFirst_ReplacesOnlyTheFirstMatch()
+ {
+ "bar bar baz".ReplaceFirst("bar", "foo").Should().Be("foo bar baz");
+ }
+ }
+}

0 comments on commit faa9715

Please sign in to comment.
Something went wrong with that request. Please try again.