使用java guava spliter分割时可能不会破坏单词吗?
我有这个样本:
var String msg = "My name is Fabio and I have a dog";
Splitter.fixedLength(5).split(msg).forEach(item -> {
System.out.println(item);
});
这将打印:
My na
me is
Fabi
o and
I ha
ve a
dog
但我希望他不要说我的话
就像这样:
My naME
is Fabio
and I have
a dog
我没有控制文本,我只想保留最后一个词为everty split
答案 0 :(得分:0)
方法调用'LabanotationAR.exe' (CoreCLR: DefaultDomain): Loaded 'c:\data\Programs\WindowsApps\Microsoft.NET.CoreRuntime.2.1_1.1.25129.1_x86__8wekyb3d8bbwe\System.Private.CoreLib.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\entrypoint\LabanotationAR.exe'. Symbols loaded.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'c:\data\Programs\WindowsApps\Microsoft.NET.CoreRuntime.3.1_1.1.25129.1_x86__8wekyb3d8bbwe\mscorlib.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\WinMetadata\Windows.winmd'. Module was built without symbols.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\UnityPlayer.winmd'. Module was built without symbols.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Runtime.InteropServices.WindowsRuntime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Runtime.WindowsRuntime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\WinRTBridge.winmd'. Cannot find or open the PDB file.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\BridgeInterface.winmd'. Module was built without symbols.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Collections.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\UnityEngine.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\Assembly-CSharp.dll'. Symbols loaded.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Threading.Tasks.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.IO.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\WinRTLegacy.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\UnityEngine.UI.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.ObjectModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\UnityEngine.Networking.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\UnityEngine.HoloLens.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\nunit.framework.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Reflection.dll'. Module was built without symbols.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\UnityEngine.Analytics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Globalization.dll'. Module was built without symbols.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Net.Primitives.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Private.Networking.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\Microsoft.Win32.Primitives.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Reflection.Primitives.dll'. Module was built without symbols.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Reflection.TypeExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Runtime.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Xml.XDocument.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Private.Uri.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Xml.ReaderWriter.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Text.Encoding.dll'. Module was built without symbols.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Text.RegularExpressions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\UnityEngine.VR.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Runtime.InteropServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Threading.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Diagnostics.Debug.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loading native plugins
Loading MicStreamSelector.dll
Loading SharingClient.dll
Loading SpatialUnderstanding.dll
Loading PlaneFinding.dll
Module information:
Built with Compiler Ver '190023918'
Built from '5.6/release' branch
Version is '5.6.1f1 (2860b30f0b54)'
Debug build
Application type 'D3D11'
Used 'UWP'
OS 'Windows 10 (10.0.14393)'
PlayerConnection initialized from C:/Data/Users/DefaultAccount/AppData/Local/DevelopmentFiles/LabanotationARVS.Debug_x86.kurtr/Data (debug = 0)
PlayerConnection initialized network socket : 0.0.0.0 55008
Multi-casting "[IP] 172.30.0.203 [Port] 55008 [Flags] 2 [Guid] 2978211851 [EditorId] 4294967295 [Version] 1048832 [Id] MetroPlayerX86(HoloLens-UAO3C) [Debug] 0" to [225.0.0.222:54997]...
Started listening to [0.0.0.0:55008]
Player data archive not found at `C:/Data/Users/DefaultAccount/AppData/Local/DevelopmentFiles/LabanotationARVS.Debug_x86.kurtr/Data/data.unity3d`, using local filesystem
GfxDevice: creating device client; threaded=1
Direct3D:
Version: Direct3D 11.0 [level 11.1]
Renderer: HoloLens Graphics (ID=0x22b0)
Vendor: Intel
VRAM: 604 MB
Initialize engine version: 5.6.1f1 (2860b30f0b54)
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\UnityEngineProxy.dll'. Cannot find or open the PDB file.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LabanotationAR.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LabanotationARVS.Debug_x86.kurtr\System.Reflection.Extensions.dll'. Module was built without symbols.
The following GlobalManagers were stripped from the build (Either because they're not used or not supported on this platform):
NetworkManager
MasterServerInterface
UnityAdsManager
ClusterInputManager
CrashReportManager
If your machine has multiple graphics adapters, Unity may have created a WindowContext on the wrong adapter. If you experience a black screen when playing, please restart the Editor.
(Filename: C:/buildslave/unity/build/Runtime/VR/VRDevice.cpp Line: 184)
UnloadTime: 25.033651 ms
WinRTScriptingObjectWrapper::InternalAddRef Reference Count cannot be zero
(Filename: C:\buildslave\unity\build\Runtime/ScriptingBackend/DotNet/ScriptingApi_DotNet.cpp Line: 661)
The program '[3492] LabanotationAR.exe' has exited with code -2147483645 (0x80000003).
将每5个字符拆分文本,这就是为什么您的文字被分成两部分,因此您无法使用此方法解决问题。你可以做的一件事是使用正则表达式作为分隔符来分隔每个空格的字符串,并使用循环来格式化输出。
fixedLength(5)
这种逻辑应该回答你的问题。
答案 1 :(得分:0)
您可以在迭代时拆分单词并构建行:
final List<String> lines = new ArrayList<>();
final StringBuilder builder = new StringBuilder();
for (String word : Splitter.on(' ').split(msg)) {
if (builder.length() == 0) {
builder.append(word);
} else if (builder.length() <= 5) {
builder.append(' ').append(word);
} else {
lines.add(builder.toString());
builder.setLength(0);
builder.append(word);
}
}
if (builder.length() > 0) {
lines.add(builder.toString());
}
lines.forEach(System.out::println);
输出:
My name
is Fabio
and I have
a dog